如何解决半径为
|的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];
当然,还有其他方法可以做到这一点。这只是一种方式。
希望能有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。