Jin Yong
Jin Yong

Reputation: 43788

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?

Upvotes: 0

Views: 2566

Answers (2)

foued611
foued611

Reputation: 359

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);
}

Upvotes: 0

danski
danski

Reputation: 353

Calculate distance between two points in google maps V3

I think you might be after something like this which has a few good answers.

Upvotes: 1

Related Questions