Created
June 27, 2013 21:21
-
-
Save umutakturk/5880519 to your computer and use it in GitHub Desktop.
Calculating distance between two geo-points.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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