Skip to content

Instantly share code, notes, and snippets.

@msenkpiel
Created January 23, 2015 11:27
Show Gist options
  • Save msenkpiel/62981fb575d6caa40f83 to your computer and use it in GitHub Desktop.
Save msenkpiel/62981fb575d6caa40f83 to your computer and use it in GitHub Desktop.
Distance
public static function distance($lat1, $lon1, $lat2, $lon2)
{
$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);
$kilometers = $dist * 60 * 1.8531596160;
return $kilometers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment