计算两个GPS坐标的距离
PHP计算两个GPS点之间的距离
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<pre class="inline:true class:language-php decode:1 " > #lng为经度,lat为纬度,一定不要弄错了哦 function distance($lat1, $lng1, $lat2, $lng2){ 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(($lng1-$lng2)*PI()/180/2) *SIN(($lng1-$lng2)*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(($lng1-$lng2)*PI()/180/2) *SIN(($lng1-$lng2)*PI()/180/2))))*6378140; } |
调用方法:
1 |
<pre class="inline:true class:language-php decode:1 " >echo distance(39.91917,116.3896,39.91726,116.3940); |
Mysql计算两GPS坐标的距离
1 2 3 |
<pre class="inline:true class:language-sql decode:1 " >drop function getDistance; DELIMITER $$ CREATE DEFINER=<pre class="inline:true decode:1 " >root |
@[crayon-668743efc00291 …