Created
December 6, 2012 19:03
-
-
Save mteece/4227195 to your computer and use it in GitHub Desktop.
Search array of locations within a radius
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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