地图上的方向

问题描述

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

解决方法

        这可能为时已晚,您可能已经解决了,但是这是我测试过并可以正常工作的解决方案。 我说,与我尝试过的其他实现相比,在大约25个目标时间内给出了结果。 newLocation是从CLLocationManagerDelegate获得的,而latlngofAnn是用户在我的应用中选择的所选MKA注释。 只需将lat和lon数据替换为数组中的what。
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;