简体   繁体   中英

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.

Any one got any idea or links to examples?

Calculate distance between two points in google maps 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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