简体   繁体   English

使用 PHP 和谷歌地图 Api 计算出 2 个纬度和经度之间的距离

[英]Using PHP and google Maps Api to work out distance between 2 latitude and longitude

Just wondering how to work out distance between 2 latitude and longitude using PHP and Google Maps Api.只是想知道如何使用 PHP 和谷歌地图 Api 计算出 2 个纬度和经度之间的距离。

Any one got any idea or links to examples?任何人有任何想法或示例链接吗?

Calculate distance between two points in google maps V3 计算谷歌地图V3中两点之间的距离

I think you might be after something like this which has a few good answers.我认为您可能正在寻找这样的东西,它有一些很好的答案。

function calcDistance($lat1,$Lang1, $lat2, $Lang2)
{
    //RAD
    $b1 = ($lat1/180)*M_PI;
    $b2 = ($lat2/180)*M_PI;
    $l1 = ($Lang1/180)*M_PI;
    $l2 = ($Lang2/180)*M_PI;
    //equatorial radius
    $r = 6378.137;
    // Formel
    $e = acos( sin($b1)*sin($b2) + cos($b1)*cos($b2)*cos($l2-$l1) );
    return round($r*$e, 4);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM