php计算两个gps点之间的距离

下面是php计算两个gps点距离的函数:

php计算两个gps点之间的距离mysql计算两gps坐标的距离javascript计算两个gps点之间的距离

#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;
}

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

echo
distance(39.91917,116.3896,39.91726,116.3940);

以上就介绍了php计算两个gps点之间的距离,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。

Posted in 未分类

发表评论