Ios4 地图上的方向

Ios4 地图上的方向,ios4,Ios4,在我的应用程序中,我在mkmapview上显示了两点之间的路线,但我想显示这两点的方向。点的纬度和长度存储在NSArray中。这可能太晚了,您可能已经解决了它,但这里有一个我已经测试过的解决方案,它确实可以正常工作 我说,正如我尝试过的其他实现一样,其结果大约为25度 newLocation是从CLLocationManagerDelegate获得的,Latlngofan是用户在我的应用程序中选择的MKAnnotation 只需将lat和lon数据替换为阵列中的数据即可 double lat2

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

这可能太晚了,您可能已经解决了它,但这里有一个我已经测试过的解决方案,它确实可以正常工作

我说,正如我尝试过的其他实现一样,其结果大约为25度

newLocation是从CLLocationManagerDelegate获得的,Latlngofan是用户在我的应用程序中选择的MKAnnotation

只需将lat和lon数据替换为阵列中的数据即可

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;
double lat2=latlngOfAnn.coordinate.lation*M_PI/180.0;
双lon2=Latlngofan.coordinate.longitude*M_PI/180.0;
双纬度1=newLocation.coordinate.lation*M_PI/180.0;
double lon1=newLocation.coordinate.longitude*M_PI/180.0;
双dLon=lon2-lon1;
双y=sin(dLon)*cos(lat2);
双x=cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(dLon);
双弧度轴承=atan2(y,x);
if(弧度轴承<0.0)
弧度轴承+=2*M_π;
双轴承=弧度轴承*180.0/M_PI;