gpt4 book ai didi

objective-c - 计算两组坐标之间的距离(NSStrings)

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:18:45 24 4
gpt4 key购买 nike

我有两组地理坐标,我正在尝试计算它们之间的距离。我已经做了一些挖掘,但无法弄清楚该怎么做。我正在尝试获取用户(userLatitude/userLongitude)和地点(placeLatitude/placeLongitude)之间的距离(以英里为单位)。我的坐标存储为 NSStrings,如下所示。有谁知道如何做到这一点?谢谢你们!

NSString *userLatitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate 
getUserLatitude];

NSString *userLongitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate
getUserLongitude];

NSString *placeLatitude = [element1 objectForKey:@"placeLatitude"];

NSString *placeLongitude = [element1 objectForKey:@"placeLongitude"];

最佳答案

这可能对您有所帮助。尝试从你拥有的经纬度创建 CLLocation

CLLocation* Location1;
CLLocation* Location2;
CLLocationDistance distance = [Location1 distanceFromLocation:Location2];

关于objective-c - 计算两组坐标之间的距离(NSStrings),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13898001/

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