function get_two_point_distance($lat1,$lat2,$lng1,$lng2)
{
$radLat1 = deg2rad($lat1);//deg2rad()函式將角度轉換為弧度
$radLat2 = deg2rad($lat2);
$radLng1 = deg2rad($lng1);
$radLng2 = deg2rad($lng2);
$a = $radLat1 - $radLat2;
$b = $radLng1 - $radLng2;
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137;
return round($s,2);//返回公里數
}
echo get_two_point_distance('30.57455367949652','30.570165917503918','104.20095642799379','104.19042607540132');
本作品採用《CC 協議》,轉載必須註明作者和本文連結