gpt4 book ai didi

iphone - 查找最近的CLLocation

转载 作者:行者123 更新时间:2023-12-01 17:41:29 25 4
gpt4 key购买 nike

如何找到距用户最近的位置?基本上,我有一堆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);

关于iphone - 查找最近的CLLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17893279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com