下面是PHP計算兩個GPS點距離的函數:
PHP計算兩個GPS點之間的距離
Mysql計算兩GPS座標的距離
javascript計算兩個GPS點之間的距離
#lon為經度,lat為緯度,一定不要弄錯了哦 function <span>distance</span>($lon1, $lat1, $lon2, $lat2){ return (2*ATAN2(SQRT(SIN(($lat1-$lat2)*PI()/180/2) *SIN(($lat1-$lat2)*PI()/180/2)+ COS($lat2*PI()/180)*COS($lat1*PI()/180) *SIN(($lon1-$lon2)*PI()/180/2) *SIN(($lon1-$lon2)*PI()/180/2)), SQRT(1-SIN(($lat1-$lat2)*PI()/180/2) *SIN(($lat1-$lat2)*PI()/180/2) +COS($lat2*PI()/180)*COS($lat1*PI()/180) *SIN(($lon1-$lon2)*PI()/180/2) *SIN(($lon1-$lon2)*PI()/180/2))))*6378140; }
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#lon為經度,lat為緯度,一定不要弄錯了哦 functiondistance($lon1,$lat1,$lon2,$lat2){ return(2*ATAN2(SQRT(SIN(($lat1-$lat2)*PI()/180/2) *SIN(($lat1-$lat2)*PI()/180/2)+ COS($lat2*PI()/180)*COS($lat1*PI()/180) *SIN(($lon1-$lon2)*PI()/180/2) *SIN(($lon1-$lon2)*PI()/180/2)), SQRT(1-SIN(($lat1-$lat2)*PI()/180/2) *SIN(($lat1-$lat2)*PI()/180/2) +COS($lat2*PI()/180)*COS($lat1*PI()/180) *SIN(($lon1-$lon2)*PI()/180/2) *SIN(($lon1-$lon2)*PI()/180/2))))*6378140; } |
調用方法:
echo distance(39.91917,116.3896,39.91726,116.3940);
1 |
echodistance(39.91917,116.3896,39.91726,116.3940); |
以上就介紹了PHP計算兩個GPS點之間的距離,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。