QT 通过经纬度计算方位角
#define PI 3.14
double ThreadToParseJson::getAngle(double lat_a, double lng_a, double lat_b, double lng_b) //lat_a表示上个点纬度, lat_b表示当前点的纬度 { double lat1 = lat_a* PI / 180.0; double lat2 = lat_b* PI / 180.0; double lon1 = lng_a* PI / 180.0; double lon2 = lng_b* PI / 180.0; double azimuth = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1); azimuth = sqrt(1 - azimuth * azimuth); azimuth = cos(lat2) * sin(lon2 - lon1) / azimuth; azimuth = asin(azimuth) * 180 / PI; if (azimuth == NAN) { if (lon1 < lon2) { azimuth = 90.0; return azimuth; } else { azimuth = 270.0; return azimuth; } } double x = lat_b - lat_a; double y = lng_b - lng_a; if(x > 0 && y > 0){ return azimuth; } else if(x < 0 && y > 0){ return 180 - azimuth; } else if(x < 0 && y < 0){ return 180 - azimuth; } else if(x > 0 && y < 0){ return 360 + azimuth; } else{ return NAN; }