计算地球表面任意两个GPS点之间的球面距离

返回单位:米

static double Distance(double lon1, double lat1, double lon2, double lat2)
{
double R = 6378137; //地球半径
lat1 = lat1 * Math.PI / 180.0;
lat2 = lat2 * Math.PI / 180.0;
double sa2 = Math.Sin((lat1 - lat2) / 2.0);
double sb2 = Math.Sin(((lon1 - lon2) * Math.PI / 180.0) / 2.0);
return 2 * R * Math.Asin(Math.Sqrt(sa2 * sa2 + Math.Cos(lat1) * Math.Cos(lat2) * sb2 * sb2));
}

你可能感兴趣的:(gps)