Skip to content

Instantly share code, notes, and snippets.

@jammin77
Last active August 29, 2015 14:07
Show Gist options
  • Save jammin77/310d52d197fec1b89300 to your computer and use it in GitHub Desktop.
Save jammin77/310d52d197fec1b89300 to your computer and use it in GitHub Desktop.
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;
}
@jammin77
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment