I did not know this for a long time. I forgot it. I saw it in a book before. But what I found on the Internet was actually a spherical distance algorithm.
Lat is the latitude, and lung is the longitude
A = Lat1-Lat2 is the difference between two points of latitude B = Lung1-Lung2 is the difference between two points of longitude;
6378.137 (KM) is the earth's radius --@
Well, the result is also km ......
In addition, google's api has actually been implemented
Java code
// Calculate the two-point distance
Private final double EARTH_RADIUS = 6378137.0;
Private double gps2m (double lat_a, double lng_a, double lat_ B, double lng_ B ){
Double radLat1 = (lat_a * Math. PI/180.0 );
Double radLat2 = (lat_ B * Math. PI/180.0 );
Double a = radLat1-radLat2;
Double B = (lng_a-lng_ B) * Math. PI/180.0;
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;
}
Author "Notepad ......"