Edu*_*rdo 1 iphone cllocationmanager cllocation ios currentlocation
如何找到距离用户最近的位置?基本上,我有一堆CLLocation,我想找到最接近用户的那个.我已检索到用户当前位置但我想找到最近的位置CLLocation.我该怎么做呢?你可以NSLog就近.
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
543 次 |
| 最近记录: |