/** * [GetDistance 计算两个进纬度之间的距离] * @param [float] $lat1 [纬度1] * @param [float] $lng1 [经度1] * @param [float] $lat2 [纬度2] * @param [float] $lng2 [经度2] * @return[float] [两个坐标距离值] */ function GetDistance($lat1, $lng1, $lat2, $lng2) { $pi = 3.1415926535898; $earth_radius = 6378.137; $radLat1 = $lat1 * ($pi / 180); $radLat2 = $lat2 * ($pi / 180); $a = $radLat1 - $radLat2; $b = ($lng1 * ($pi / 180)) - ($lng2 * ($pi / 180)); $s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1)*cos($radLat2)*pow(sin($b/2),2))); $s = $s * $earth_radius; $s = round($s * 10000) / 10000; return $s; }
发表评论: