Skip to content

Instantly share code, notes, and snippets.

@FluxCoder
Created March 26, 2019 20:04
Show Gist options
  • Save FluxCoder/2c9b02455eb0b34bfe523f0c7ca0bace to your computer and use it in GitHub Desktop.
Save FluxCoder/2c9b02455eb0b34bfe523f0c7ca0bace to your computer and use it in GitHub Desktop.
Calculate the distance between 2 coordinates
<?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