Skip to content

Instantly share code, notes, and snippets.

@mteece
Created December 6, 2012 19:03
Show Gist options
  • Select an option

  • Save mteece/4227195 to your computer and use it in GitHub Desktop.

Select an option

Save mteece/4227195 to your computer and use it in GitHub Desktop.
Search array of locations within a radius
// NSArray *locations as an array of CLLocation* that you wish to filter
// with a given radius constant.
CLLocationDistance radius = kSomeRadius;
// Target you want to test against to see if it is within the radius bounds.
CLLocation* target = [[CLLocation alloc] initWithLatitude:someLat longitude:someLon];
NSArray *locationsWithinRadius = [locations objectsAtIndexes:
[locations indexesOfObjectsPassingTest:
^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return [(CLLocation*)obj distanceFromLocation:target] < radius;
}]];
// Return locationsWithinRadius.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment