根据任意两点地图坐标算出距离是多少
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 private static double rads(double d) 2 { 3 return d*Math.PI/180.0; 4 } 5 6 private const double EarihRadius = 6378.137; 7 8 private static double GetDistances(double lat1, double lng1, double lat2, double lng2) 9 { 10 var radLat1 = rads(lat1); 11 var radLat2 = rads(lat2); 12 var lat = radLat1 - radLat2; 13 var lng = rads(lng1) - rads(lng2); 14 var s = 2* 15 Math.Asin( 16 Math.Sqrt(Math.Pow(Math.Sin(lat/2), 2) + 17 Math.Cos(radLat1)*Math.Cos(radLat2)*Math.Pow(Math.Sin(lng/2), 2))); 18 s = s*EarihRadius; 19 return Math.Round(s*10000)/10000; 20 } 21 22 23 /// 24 var c = GetDistances( 39.90408611111111,116.29571388888888, 39.9061185, 116.297728); 25 Console.WriteLine(c);