Here is the function of PHP to calculate the distance of two GPS points:
PHP calculates the distance between two GPS points
MySQL calculates the distance between two GPS coordinates
JavaScript calculates the distance between two GPS points
#lon为经度, lat is latitude, must not be mistaken Oh function <span>distance</span> ($lon 1, $lat 1, $lon 2, $lat 2) {return (2*atan2 (SQRT (SIN (($lat 1-$lat 2) *pi ()/180/2) *sin (($lat 1-$lat 2) *pi ()/180/2) + COS ($lat 2*pi ()/180) *cos ($lat 1*pi ()/180) *sin (($lon 1-$lon 2) *pi ()/180/2) *sin (($lon 1-$lon 2) *pi ()/180/2), SQRT (1-sin (($lat 1-$lat 2) *pi ()/180/2) *sin (($lat 1-$lat 2) *pi ()/180/2) +cos ($lat 2*pi ()/180) *cos ($lat 1*pi ()/180) *sin (($lon 1-$lon 2) *pi ()/180/2 ) *sin (($lon 1-$lon 2) *pi ()/180/2)))) *6378140; }
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#lon为经度, Lat is the latitude, must not be mistaken oh functiondistance($lon1,$lat1 ,$lon2,$lat2){ return(2*ATAN2(SQRT (SIN($lat1-$lat2 )*PI() / 2) *SIN($lat1-$lat2 )*PI()/2 )+ COS($lat2*PI()/ *COS($lat1*PI) ()/+) *SIN($lon1-$ lon2)*PI()/ / 2 ) *SIN($lon1-$lon2 )*PI()/2 )), SQRT(1-SIN($ lat1-$lat2)*PI( )/2) *SIN($lat1-$ lat2)*PI()/ / 2 ) +COS($lat2*PI()/ the )*COS($lat1*PI() /+) *SIN($lon1-$ lon2)*PI()/ / 2 ) *SIN($lon1-$lon2 )*PI()/2 )))*6378140; } |
Call Method:
echo distance (39.91917,116.3896,39.91726,116.3940);
1 |
Echo Distance (39.91917,116.3896,39.91726, 116.3940); |
The above describes the PHP calculation of the distance between two GPS points, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.