根据经纬度计算球面距离

double zz(double s)
{
    return (s * 3.1415927 / 180.0);
}

double sqr(double s)
{
    return s * s;
}

double distance(double alongitude, double alatitude, double blongitude, double blatitude)
{
    double earth_radius = 6378137.0;
    double a = zz(alatitude) - zz(blatitude);
    double b = zz(alongitude) - zz(blongitude);
    double s = 2 * asin(sqrt(sqr(sin(a / 2)) + cos(zz(alatitude)) * cos(zz(blatitude)) * sqr(sin(b / 2))));
    s *= earth_radius;
    return s;

}

你可能感兴趣的:(根据经纬度计算球面距离)