php计算经纬度距离,php经纬度计算距离
/**
*?計算兩點地理坐標之間的距離
*?@param??Decimal?$longitude1?起點經度
*?@param??Decimal?$latitude1??起點緯度
*?@param??Decimal?$longitude2?終點經度
*?@param??Decimal?$latitude2??終點緯度
*?@param??Int?????$unit???????單位?1:米?2:公里
*?@param??Int?????$decimal????精度?保留小數位數
*?@return?Decimal
*/
function?getDistance($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;
}
return?round($distance,?$decimal);
}
總結
以上是生活随笔為你收集整理的php计算经纬度距离,php经纬度计算距离的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 喜马拉雅现罕见精灵闪电:如同一只红色大水
- 下一篇: 周杰伦7月15日发新专辑 新专辑名字或