Skip to content

Instantly share code, notes, and snippets.

@affix
Created January 13, 2014 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save affix/8396464 to your computer and use it in GitHub Desktop.
Save affix/8396464 to your computer and use it in GitHub Desktop.
public function DistAB($lata, $lona, $latb, $lonb)
{
$delta_lat = $latb - $lata ;
$delta_lon = $lonb - $lona ;
$earth_radius = 6372.795477598;
$alpha = $delta_lat/2;
$beta = $delta_lon/2;
$a = sin(deg2rad($alpha)) * sin(deg2rad($alpha)) + cos(deg2rad($lata)) * cos(deg2rad($latb)) * sin(deg2rad($beta)) * sin(deg2rad($beta)) ;
$c = asin(min(1, sqrt($a)));
$distance = 2*$earth_radius * $c;
$distance = round($distance, 4);
return $distance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment