gpt4 book ai didi

ios4 - map 方向

转载 作者:行者123 更新时间:2023-12-05 01:23:39 26 4
gpt4 key购买 nike

我在我的应用程序中的 mkmapview 上显示了两点之间的路线,但我想显示这两点的方向。点的纬度和经度存储在 NSArray 中。

最佳答案

这可能为时已晚,您可能已经解决了它,但这是我已经测试过并且可以正常工作的解决方案。

我说的是,我尝试过的其他实现方案的结果相差大约 25 度。

newLocation 是从 CLLocationManagerDelegate 获得的,而 latlngofAnn 是用户在我的应用程序中选择的选定 MKAnnotation。

只需用数组中的内容替换纬度和经度数据即可。

double lat2 =  latlngOfAnn.coordinate.latitude * M_PI / 180.0;
double lon2 = latlngOfAnn.coordinate.longitude * M_PI / 180.0;
double lat1 = newLocation.coordinate.latitude * M_PI / 180.0;
double lon1 = newLocation.coordinate.longitude * M_PI / 180.0;

double dLon = lon2 - lon1;
double y = sin(dLon) * cos(lat2);
double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon);
double radiansBearing = atan2(y, x);

if(radiansBearing < 0.0)
radiansBearing += 2*M_PI;

double bearing = radiansBearing * 180.0 / M_PI;

关于ios4 - map 方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6458497/

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