Created
July 24, 2012 10:52
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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