/// <summary> /// 获取两个坐标点的距离
/// </summary>
/// <param name="lat1">坐标1的维度</param>
/// <param name="lng1">坐标1的经度</param>
/// <param name="lat2">坐标2的维度</param>
/// <param name="lng2">坐标2的经度</param>
/// <returns>返回两点间的距离,单位米</returns>
public static double GetDistance(decimal lat1, decimal lng1, decimal lat2, decimal lng2)
{
double radLat1 = rad((double)lat1);
double radLat2 = rad((double)lat2);
double a = radLat1 - radLat2;
double b = rad((double)lng1) - rad((double)lng2);
double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) +Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2))); s = s * EARTH_RADIUS;
s = Math.Round(s * 10000) / 10000;
return s;
}
}
}
时间: 2024-11-08 19:17:43