/** * Calculates the distance between two groups of latitude * params:lat1 latitude 1,lng1 longitude 1,lat2 latitude 2,lng2 degrees 2,len_type (1:m|2:km); * Echo getdistance ($lat 1, $lng 1, $lat 2, $LNG 2). ' M '; */function getdistance ($lat 1, $lng 1, $lat 2, $lng 2, $len _type=1, $decimal =2) {$EARTH _radius=6378.137;//the Earth's half diameter, assuming the earth is the rule of the ball $PI =3.1415926;//Frequency $RADLAT1 = $lat 1 * $PI/180.0; $radLat 2 = $lat 2 * $PI/180.0; $a = $radLat 1-$radLat 2; $b = ($l NG1 * $PI/180.0)-($lng 2 * $PI/180.0); $s = 2 * ASIN (sqrt (Pow (sin ($a/2), 2) + cos ($radLat 1) * cos ($radLat 2) * POW (sin ($ B/2), 2)); $s = $s * $EARTH _radius; $s = round ($s *1000), if ($len _type>1) { $s/= 1000;} Return round ($s, $decimal);}
The above describes the calculation of the distance between the two groups of latitude, including the aspects of the content, I hope to be interested in the PHP tutorial friends helpful.