Objective-c搜索具有半径的位置 [英] Objective-c search locations with radius
本文介绍了Objective-c搜索具有半径的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个用于objective-c的库,它将允许我指定一个半径和一个位置,以及一个位置列表,并告诉我哪些位置在该半径范围内?
谢谢。
Is there a library in for objective-c that will allow me to specify a radius and a location, and a list of locations and tell me which locations are within that radius? Thanks.
推荐答案
如果你有CLLocations,那么类似这样的东西可以工作:
If you have CLLocations then something like this would work:
// 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];
当然还有其他方法。这只是一种方式。
There are other ways to do this of course. This is just one way.
希望有帮助。
这篇关于Objective-c搜索具有半径的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文