Skip to content

Instantly share code, notes, and snippets.

@umutakturk
Created June 27, 2013 21:21
Show Gist options
  • Save umutakturk/5880519 to your computer and use it in GitHub Desktop.
Save umutakturk/5880519 to your computer and use it in GitHub Desktop.
Calculating distance between two geo-points.
<?php
function distance($fromLat, $fromLon, $toLat, $toLon) {
$radius = 6378.1; // 3963.17 miles
$dLat = deg2rad($toLat - $fromLat);
$dLon = deg2rad($toLon - $fromLon);
$tmp = cos(deg2rad(($fromLat + $toLat) / 2)) * $dLon;
$distance = $radius * sqrt($dLat * $dLat + $tmp * $tmp);
return round($distance, 1);
}
echo distance(41.00518, 28.97702, 39.948701, 32.857361);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment