Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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