Skip to content

Instantly share code, notes, and snippets.

@gsdevme
Created July 24, 2012 10:52
Show Gist options
  • Save gsdevme/3169369 to your computer and use it in GitHub Desktop.
Save gsdevme/3169369 to your computer and use it in GitHub Desktop.
. Storing this here incase the location goes down. http://de.60.5646.static.theplanet.com/samples/distance.php.html
/**
* This section of code was taken from here
* http://de.60.5646.static.theplanet.com/samples/distance.php.html
*/
function calcDistance($lat, $long2, $lat2, $long2, $unit='m')
{
$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);
switch($unit){
case 'K':
return ($miles * 1.609344);
case 'N':
return ($miles * 0.8684);
default:
return $miles;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment