如何找到离用户最近的位置?基本上,我有一堆CLLocation
's,我想找到最接近用户的一个。我已检索到用户当前位置,但我想找到最近的CLLocation
. 我该怎么做呢?你可以只是NSLog
最接近的。
问问题
563 次
1 回答
7
CLLocation *currentLocation;
NSArray *otherLocations;
CLLocation *closestLocation;
CLLocationDistance closestDistance = DBL_MAX;
for (CLLocation* location in otherLocations) {
CLLocationDistance distance = [currentLocation distanceFromLocation:location];
if (distance < closestDistance) {
closestLocation = location;
closestDistance = distance;
}
}
NSLog(@"the closest location is %@", closestLocation);
于 2013-07-27T01:43:52.910 回答