1 回答

TA貢獻1827條經驗 獲得超8個贊
我認為是因為你以英里為單位使用該功能,在公里中你可以使用類似的東西:
public static function distance(
array $from,
array $to
) {
if (empty($from['lat']) || empty($to['lat'])) {
return $to['distance'];
}
$latitude1 = (float) $from['lat'];
$latitude2 = (float) $to['lat'];
$longitude1 = (float) $from['lng'];
$longitude2 = (float) $to['lng'];
$theta = $longitude1 - $longitude2;
$distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2)))
+ (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)))
;
$distance = acos($distance);
$distance = rad2deg($distance);
$distance = $distance * 60 * 1.1515;
$distance = (is_nan($distance)) ? 0 : $distance * 1.609344;
return $distance;
}
- 1 回答
- 0 關注
- 272 瀏覽
添加回答
舉報