PHP Code: Reprint http://www.cnblogs.com/caichenghui/p/5977431.html
1 /**2 * Find the distance between two known longitude and latitude, in meters3 * 4 * @param lng1 $, lng2 longitude5 * @param lat1 $, lat2 latitude6 * @return float distance, Unit meter7 * @author www.Alixixi.com8 */9 functionGetdistance ($LNG 1,$lat 1,$LNG 2,$lat 2) {Ten //turn angle into Fox degree One $radLat 1=Deg2rad($lat 1);//the Deg2rad () function converts an angle to radians A $radLat 2=Deg2rad($lat 2); - $radLng 1=Deg2rad($LNG 1); - $radLng 2=Deg2rad($LNG 2); the $a=$radLat 1-$radLat 2; - $b=$radLng 1-$radLng 2; - $s= 2 *ASIN(sqrt(POW(Sin($a/2), 2) +Cos($radLat 1) *Cos($radLat 2) *POW(Sin($b/2), 2)) * 6378.137 * 1000; - return $s; +}
JavaScript code:
1 //return Unit m2 get_distance (lat1,lng1,lat2,lng2) {3 varRADLAT1 = LAT1 * math.pi/180.0;4 varRADLAT2 = Lat2 * math.pi/180.0;5 varA = RADLAT1-RadLat2;6 varb = lng1 * Math.pi/180.0-lng2 * math.pi/180.0;7 vars = 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)));8s = S * 6378.137;9s = Math.Round (S * 10000)/10000;Tens = s*1000; One returns; A},
The latitude and longitude of two points are known, and the distance between two points is calculated (Php,javascript)