Iphone 查找最近的位置
如何找到离用户最近的位置?基本上,我有一堆CLLocation,我想找到最接近用户的一个。我已检索到用户的当前位置,但我想找到最近的位置。我该怎么做呢?您可以只记录最近的距离。更新ClosesLocation时需要更新ClosesDistance更新ClosesLocation时需要更新ClosesDistanceIphone 查找最近的位置,iphone,ios,cllocationmanager,cllocation,currentlocation,Iphone,Ios,Cllocationmanager,Cllocation,Currentlocation,如何找到离用户最近的位置?基本上,我有一堆CLLocation,我想找到最接近用户的一个。我已检索到用户的当前位置,但我想找到最近的位置。我该怎么做呢?您可以只记录最近的距离。更新ClosesLocation时需要更新ClosesDistance更新ClosesLocation时需要更新ClosesDistance CLLocation *currentLocation; NSArray *otherLocations; CLLocation *closestLocation; CLLocat
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);