1 /// <summary> 2 /// 经纬度转换为弧度 3 /// </summary> 4 /// <param name="d">经度/纬度</param> 5 /// <returns></returns> 6 private static double Rad(double d) 7 { 8 return d * Math.PI / 180.0; 9 } 10 /// <summary> 11 /// 计算两点之间的距离,单位公里 12 /// </summary> 13 /// <param name="lat1">第一点经度</param> 14 /// <param name="lng1">第一点纬度</param> 15 /// <param name="lat2">第二点经度</param> 16 /// <param name="lng2">第二点纬度</param> 17 /// <returns></returns> 18 public static double GetDistance(double lat1, double lng1, double lat2, double lng2) 19 { 20 double num1 = Rad(lat1) - Rad(lat2); 21 double num2 = Rad(lng1) - Rad(lng2); 22 return Math.Round(2.0 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(num1 / 2.0), 2.0) + Math.Cos(d1) * Math.Cos(d2) * Math.Pow(Math.Sin(num2 / 2.0), 2.0))) * (以公里为单位的地球半径) * 10000.0) / 10000.0; 23 }
标签:Rad,经纬度,C#,double,经度,两点,2.0,Math From: https://www.cnblogs.com/wynblogscc/p/17340443.html