PHP 计算两经纬度之间距离
<?php
/*
$lat1 纬度A
$lon1 经度A
$lat2 纬度B
$lon2 经度B
*/
function nearby_distance($lat1, $lon1, $lat2, $lon2) {
$EARTH_RADIUS = 6378.137;
$radLat1 = rad($lat1);
$radLat2 = rad($lat2);
$a = $radLat1 - $radLat2;
$b = rad($lon1) - rad($lon2);
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
$s1 = $s * $EARTH_RADIUS;
$s2 = round($s1 * 10000) / 10000;
return $s2;
//print_r($s2);
}
function rad($d) {
return $d * 3.1415926535898 / 180.0;
}
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »