Recently do something encountered to be based on the two-point latitude and longitude of the distance between the calculation, on-line looked up the next information. Because this kind of contact is relatively few, directly to find the ready-made code, not how to study. The code is as follows, as a record.
Private Const Double Earth_radius = 6378.137;//Earth radius private static double rad (double D) { return d * math.pi/180.0;} public static double Getdistance (double lat1, double lng1, double lat2, double lng2) { double radLat1 = rad (LAT1); Double radLat2 = rad (LAT2); Double A = RADLAT1-RADLAT2; Double b = rad (lng1)-Rad (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;}
Note: Here is the kilometer returned, if you need to be accurate to the meter of the words themselves or take a 1000 can, we all understand it.