下面是PHP计算两个GPS点距离的函数:
PHP计算两个GPS点之间的距离
Mysql计算两GPS坐标的距离
javascript计算两个GPS点之间的距离
#lon为ç»åº¦ï¼lat为纬度ï¼ä¸å®ä¸è¦å¼éäºå¦ function <span class='wp_keywordlink_affiliate'><a href="http://www.aiezu.com/tag/distance" title="æ¥ç distance ä¸çå¨é¨æç« " target="_blank">distance</a></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为纬度,一定不要弄错了哦 function distance($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 | echo distance(39.91917,116.3896,39.91726,116.3940); |