根据经纬度计算两点之间的距离函数来源于人人源码源码收藏方便程序开发使用
//参数说明:lat1 纬度1; lng1 经度1; lat2 纬度2; lng2 经度2; len_type (1:m or 2:km);
public function GetDistance($lat1, $lng1, $lat2, $lng2, $len_type = 1, $decimal = 2)
{
$pi = 3.1415926000000001;
$er = 6378.1369999999997;
$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 * $er;
$s = round($s * 1000);
if (1 < $len_type)
{
$s /= 1000;
}
return round($s, $decimal);
}详细推导过程参考:https://blog.csdn.net/xiejm2333/article/details/73297004
如果本文对你有帮助,欢迎打赏本站

支付宝扫码打赏
微信扫码打赏
