Created
August 9, 2017 19:01
-
-
Save gauravrai1/ed3d5a44b9149df5e59cb632c9ee9768 to your computer and use it in GitHub Desktop.
haversini formula - PHP working
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 getDistance($latitude1, $longitude1, $latitude2, $longitude2) { | |
$earth_radius = 6371; | |
$distanceLat = deg2rad($latitude2 - $latitude1); | |
$distanceLon = deg2rad($longitude2 - $longitude1); | |
//part1 of the formula | |
$part1 = sin($distanceLat/2) * sin($distanceLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($distanceLon/2) * sin($distanceLon/2); | |
//part2 of the formula | |
$part2 = 2 * asin(sqrt($part1)); | |
//part3 of the formula | |
$result = $earth_radius * $part2; | |
//return value | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment