Last active
August 29, 2015 14:07
-
-
Save jammin77/310d52d197fec1b89300 to your computer and use it in GitHub Desktop.
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
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) { | |
$earth_radius = 6371; | |
$dLat = deg2rad($latitude2 - $latitude1); | |
$dLon = deg2rad($longitude2 - $longitude1); | |
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon/2) * sin($dLon/2); | |
$c = 2 * asin(sqrt($a)); | |
$d = $earth_radius * $c; | |
return $d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a a PHP Function to calculate distinances for the lat lon using the Haversine formula.
Geocode your customers address data fist and use this to calculate the nearest 7/11.
Serveal useful applications for this, go nuts and build something crazy!