Mike 发表于 2021-7-11 10:55:01

计算两点经纬度点的之间的距离和方向角,正北为0度

double GetDistance(double lat1, double lng1, double lat2, double lng2)
{
   double angle = PI/180.0;
    return (2*asin(sqrt(pow(sin((lat1-lat2)*angle/2),2) + cos(lat1*angle)*cos(lat2*angle)*pow(sin((lng1-lng2)*angle/2),2))))*6378.137;//地球半经:6378.137Km
}

int GeoAngle(double lat1, double lon1, double lat2, double lon2)
{
    double angle = 3.14159265358979324/180;
    double dY = cos(lon2*angle) * sin(lat2*angle - lat1*angle);
    double dX = cos(lon1*angle) * sin(lon2*angle) - sin(lon1*angle) * cos(lon2*angle) * cos(lat2*angle - lat1*angle);
    int dirE0 = 180 * atan2(dY, dX) / 3.14159265358979324;
    if (dirE0 < 0)
    {
      dirE0 = dirE0 + 360; //0~360
    }
    int dirN0 = (dirE0 + 90) % 360;
    return (dirN0);
}
  
文档来源:51CTO技术博客https://blog.51cto.com/u_15298588/3033976
页: [1]
查看完整版本: 计算两点经纬度点的之间的距离和方向角,正北为0度