Skip to content

Instantly share code, notes, and snippets.

@barinbritva
Created January 31, 2014 14:11
Show Gist options
  • Save barinbritva/8732735 to your computer and use it in GitHub Desktop.
Save barinbritva/8732735 to your computer and use it in GitHub Desktop.
Detect distance between geo points.
function deg2rad (angle) {
return angle * .017453292519943295;
}
function distance($lat1,$lng1,$lat2,$lng2)
{
$lat1=deg2rad($lat1);
$lng1=deg2rad($lng1);
$lat2=deg2rad($lat2);
$lng2=deg2rad($lng2);
$delta_lat=($lat2 - $lat1);
$delta_lng=($lng2 - $lng1);
return round(6378137 * acos(cos($lat1) * cos($lat2) * cos($lng1 - $lng2) + sin($lat1) * sin($lat2)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment