\n";
// COMPUTE THE DISTANCE BETWEEN TWO LAT/LON PAIRS
// MAN PAGE: http://en.wikipedia.org/wiki/Haversine_formula
function compute_distance($from_lat, $from_lon, $to_lat, $to_lon, $units='KM')
{
$units = strtoupper(substr(trim($units),0,1));
// ENSURE THAT ALL ARE FLOATING POINT VALUES
$from_lat = floatval($from_lat);
$from_lon = floatval($from_lon);
$to_lat = floatval($to_lat);
$to_lon = floatval($to_lon);
// IF THE SAME POINT
if ( ($from_lat == $to_lat) && ($from_lon == $to_lon) )
{
return 0.0;
}
// COMPUTE THE DISTANCE WITH THE HAVERSINE FORMULA
$distance
= acos
( sin(deg2rad($from_lat))
* sin(deg2rad($to_lat))
+ cos(deg2rad($from_lat))
* cos(deg2rad($to_lat))
* cos(deg2rad($from_lon - $to_lon))
)
;
$distance = rad2deg($distance);
// DISTANCE IN MILES AND KM - ADD OTHERS IF NEEDED
$miles = (float) $distance * 69.0;
$km = (float) $miles * 1.61;
// RETURN MILES
if ($units == 'M') return round($miles,1);
// RETURN KILOMETERS = MILES * 1.61
if ($units == 'K') return round($km,2);
}
if (!empty($_GET))
{
$distance = compute_distance($_GET["a_lat"], $_GET["a_lon"], $_GET["b_lat"], $_GET["b_lon"], $_GET["units"]);
echo $distance . ' ' . $_GET["units"];
}
?>
Camp David
La Maison Blanche
L'EXAMINER ICI :
DIRIGER UN LAT LON
DIRIGER LE LAT DE B LON
Milles
Kilomètres
|