function radian($d) { $d * 3.1415926535898 / 180.0; } function distance_calculate($longitude1, $latitude1, $longitude2, $latitude2) { $radLat1 = adian ( $latitude1 ); $radLat2 = radian ( $latitude2 ); $a = radian ( $latitude1 ) - radian ( $latitude2 ); $b = radian ( $longitude1 ) - radian ( $longitude2 ); $s = 2 * asin ( sqrt ( pow ( sin ( $a / 2 ), 2 ) + cos ( $radLat1 ) * cos ( $radLat2 ) * pow ( sin ( $b / 2 ), 2 ) ) ); $s = $s * 6378.137; //乘上地球半径,单位为公里 $s = round ( $s * 10000 ) / 10000; //单位为公里(km) return $s; //单位为km }
时间: 2024-10-13 12:40:31