<?php
// The following function including the comment immediately before it
// is verbatim from David Weiss's app.
// Function to calculate the distance between two points using Haversine formula
function calculateDistance($lat1, $lng1, $lat2, $lng2)
{
$earthRadius = 6371;
$latFrom = deg2rad($lat1);
$lonFrom = deg2rad($lng1);
$latTo = deg2rad($lat2);
$lonTo = deg2rad($lng2);
$latDelta = $latTo - $latFrom;
$lonDelta = $lonTo - $lonFrom;
$distance =
2 *
$earthRadius *
asin(
sqrt(
pow(sin($latDelta / 2), 2) +
cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)
)
);
return $distance;
}
// End quote from David Weiss's app
$fSydneyLat = -33.86882;
$fSydneyLon = 151.209296;
$fSantiagoLat = -33.393002;
$fSantiagoLon = -70.785797;
$fDistKM = calculateDistance($fSydneyLat, $fSydneyLon, $fSantiagoLat, $fSantiagoLon);
$fDistMiles = $fDistKM / 1.609344;
echo "Sydney to Santiago: " . $fDistKM . " km\n";
echo "Sydney to Santiago: " . $fDistMiles . " miles";
?>