/** * @desc 根據(jù)兩點間的經(jīng)緯度計算距離 * @param float $lat 緯度值 * @param float $lng 經(jīng)度值 */function getDistance($lat1, $lng1, $lat2, $lng2){ $earthRadius = 6367000; //approximate radius of earth in meters /* Convert these degrees to radians to work with the formula */ $lat1 = ($lat1 * pi()) / 180; $lng1 = ($lng1 * pi()) / 180; $lat2 = ($lat2 * pi()) / 180; $lng2 = ($lng2 * pi()) / 180; /* Using the Haversine formula http://en.wikipedia.org/wiki/Haversine_formula calculate the distance */ $calcLongitude = $lng2 – $lng1; $calcLatitude = $lat2 – $lat1; $stepOne = pow(sin($calcLatitude / 2), 2) cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); $stepTwo = 2 * asin(min(1, sqrt($stepOne))); $calculatedDistance = $earthRadius * $stepTwo; return round($calculatedDistance);}
版權聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻,該文觀點僅代表作者本人。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權/違法違規(guī)的內(nèi)容, 請發(fā)送郵件至89291810@qq.com舉報,一經(jīng)查實,本站將立刻刪除。
贊 (0)
2024高考7篇押題作文!恭喜你在考前刷到 ???
上一篇
2024年4月4日 上午10:04
形容聲音大的成語匯總(形容聲音大的成語還有哪些)
下一篇
2024年4月4日 上午10:10