Created
February 22, 2017 20:15
-
-
Save jtwiest/d37f55032ca240a049ca32c2c55dfd47 to your computer and use it in GitHub Desktop.
Return the distance between two points
This file contains hidden or 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
/** | |
* Returns the distance between two given lat / lngs | |
* in miles. | |
* | |
* @params float $lat1 | |
* @params float $lng1 | |
* @params float $lat2 | |
* @params float $lng2 | |
* @return float | |
*/ | |
public static function calculateDistance($lat1, $lng1, $lat2, $lng2) | |
{ | |
$theta = $lng1 - $lng2; | |
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); | |
$dist = acos($dist); | |
$dist = rad2deg($dist); | |
$miles = $dist * 60 * 1.1515; | |
return $miles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment