Skip to content

Instantly share code, notes, and snippets.

@tpatch
Last active October 7, 2015 02:38
Show Gist options
  • Save tpatch/99b2e3cda601a058a280 to your computer and use it in GitHub Desktop.
Save tpatch/99b2e3cda601a058a280 to your computer and use it in GitHub Desktop.
function calcDistance($userLat, $userLon) {
$storeLat = ;
$storeLon = ;
$radlat1 = pi() * $userLat / 180;
$radlat2 = pi() * $storeLat / 180;
$radlon1 = pi() * $userLon / 180;
$radlon2 = pi() * $storeLon / 180;
$theta = $userLat - $storeLat;
$radtheta = pi() * $theta / 180;
$dist = sin($radlat1) * sin($radlat2) + cos($radlat1) * cos($radlat2) * cos($radtheta);
$dist = acos($dist);
$dist = $dist * 180 / pi();
$dist = $dist * 60 * 1.1515;
$dist = $dist / 10;
return $dist;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment