Skip to content

Instantly share code, notes, and snippets.

@m1r0
Created May 2, 2014 07:40
Show Gist options
  • Save m1r0/6048c9c8f55d86eb0d0e to your computer and use it in GitHub Desktop.
Save m1r0/6048c9c8f55d86eb0d0e to your computer and use it in GitHub Desktop.
PHP: Lat/Lng Distance Calculator
function crb_calculate_location_distance($latitude1, $longitude1, $latitude2, $longitude2) {
$theta = $longitude1 - $longitude2;
$miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$miles = acos($miles);
$miles = rad2deg($miles);
$miles = $miles * 60 * 1.1515;
// $feet = $miles * 5280;
// $yards = $feet / 3;
// $kilometers = $miles * 1.609344;
// $meters = $kilometers * 1000;
return $miles;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment