半径为

问题描述

|的Objective-c搜索位置 是否有用于Objective-C的库,该库可让我指定半径和位置以及位置列表,并告诉我该半径内的位置? 谢谢。     

解决方法

        如果您有CLLocations,则可以执行以下操作:
// Given NSArray *locations as an array of CLLocation* that you wish to filter

// and given a radius...
CLLocationDistance radius = kSomeRadius;

// and given a target you want to test against...
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;

                                  }]];

[target release];
当然,还有其他方法可以做到这一点。这只是一种方式。 希望能有所帮助。