gpt4 book ai didi

objective-c - 计算用户位置与固定位置之间的距离

转载 作者:可可西里 更新时间:2023-11-01 03:35:25 25 4
gpt4 key购买 nike

我正在从服务器接收多家餐厅的纬度/经度。我想计算每个餐厅与用户当前纬度/经度之间的距离。

最佳答案

您可以使用 distanceFromLocation: CLLocation 的方法,它返回两个 CLLocation 之间的距离(以米为单位)。

CLLocation *currentLoc = /* Assume you have found it */;
CLLocation *restaurantLoc = [[CLLocation alloc] initWithLatitude:restaurantLat longitude:restaurantLng];
CLLocationDistance meters = [restaurantLoc distanceFromLocation:currentLoc];
// Go ahead with this

关于objective-c - 计算用户位置与固定位置之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7658621/

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