1 private double rad(double d) 2 { 3 return d * Math.PI / 180.0; 4 } 5 6 public double getDistance(double lat1, double lng1, double lat2, 7 double lng2) 8 { 9 double radLat1 = rad(lat1); 10 double radLat2 = rad(lat2); 11 double a = radLat1 - radLat2; 12 double b = rad(lng1) - rad(lng2); 13 double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) 14 + Math.Cos(radLat1) * Math.Cos(radLat2) 15 * Math.Pow(Math.Sin(b / 2), 2))); 16 s = s * 6378.137; 17 s = Math.Round(s * 10000); 18 s = s / 10000; 19 return s ;//计算单位:公里 20 }