Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

Not an issue but could you could use #10

Open
Klinenator opened this issue Sep 10, 2012 · 0 comments
Open

Not an issue but could you could use #10

Klinenator opened this issue Sep 10, 2012 · 0 comments

Comments

@Klinenator
Copy link

function distance($lat1, $lon1, $lat2, $lon2, $unit) {

    $theta = $lon1 - $lon2;
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    $unit = strtoupper($unit);

    if ($unit == "K") {
        return ($miles * 1.609344);
    } else if ($unit == "N") {
        return ($miles * 0.8684);
    } else {
        return substr($miles,0,3);
    }

}

Here is code that will calculate the distance between two distances if you want it.
Nice for seeing how far a place is from you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant