Created
March 26, 2019 20:04
-
-
Save FluxCoder/2c9b02455eb0b34bfe523f0c7ca0bace to your computer and use it in GitHub Desktop.
Calculate the distance between 2 coordinates
This file contains hidden or 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
<?php | |
/* | |
* Calculate the distance between 2 coordinates | |
* By James Roffey - https://jroffey.me | |
*/ | |
function distance($start, $last){ | |
$theta = $start[1] - $end[1]; | |
$dist = sin(deg2rad($start["0"])) * sin(deg2rad($last[0])) + cos(deg2rad($start[0])) * cos(deg2rad($last[0])) * cos(deg2rad($theta)); | |
$dist = acos($dist); | |
$dist = rad2deg($dist); | |
$miles = $dist * 60 * 1.1515; | |
return $miles; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment