1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > php计算经纬度距离 php经纬度计算距离

php计算经纬度距离 php经纬度计算距离

时间:2023-05-06 13:17:33

相关推荐

php计算经纬度距离 php经纬度计算距离

/**

*计算两点地理坐标之间的距离

*@paramDecimal$longitude1起点经度

*@paramDecimal$latitude1起点纬度

*@paramDecimal$longitude2终点经度

*@paramDecimal$latitude2终点纬度

*@paramInt$unit单位1:米2:公里

*@paramInt$decimal精度保留小数位数

*@returnDecimal

*/

functiongetDistance($longitude1,$latitude1,$longitude2,$latitude2,$unit=2,$decimal=2){

$EARTH_RADIUS=6370.996;//地球半径系数

$PI=3.1415926;

$radLat1=$latitude1*$PI/180.0;

$radLat2=$latitude2*$PI/180.0;

$radLng1=$longitude1*$PI/180.0;

$radLng2=$longitude2*$PI/180.0;

$a=$radLat1-$radLat2;

$b=$radLng1-$radLng2;

$distance=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)));

$distance=$distance*$EARTH_RADIUS*1000;

if($unit==2){

$distance=$distance/1000;

}

returnround($distance,$decimal);

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。