int lat_lon_dist(lat1, lon1, lat2, lon2 [, emperic]) -- Calculate the distance between two coordinates.
<?php |
This will output:
Distance from New York to Paris is 5828.092745214km. |
Published under the terms of the GPL
<?php
function lat_lon_dist($lat1, $lon1, $lat2, $lon2, $emperic = false) {
$dist = acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon1 - $lon2)));
$dist = rad2deg($dist);
$miles = $dist * 69;
if ($emperic !== false) { return $miles; }
else { return $miles * 1.609344; }
}
?>
Last updated: Sat Jun 14 20:02:45 CEST 2008