Skip to content

Instantly share code, notes, and snippets.

@abarth500
Created June 1, 2012 10:04
Show Gist options
  • Save abarth500/2850913 to your computer and use it in GitHub Desktop.
Save abarth500/2850913 to your computer and use it in GitHub Desktop.
Direction of two points
<?php
function getDirection($point1,$point2){
$lat1 = $point1->lat;
$lng1 = $point1->lng;
$lat2 = $point1->lat;
$lng2 = $point1->lng;
$Y = cos($lat2) * sin($lng2 - $lng1);
$X = cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($lng2 - $lng1);
$a = atan2($Y, $X);
if($a <0){
$a += 2 * M_PI;
}
$a = $a * 180 / M_PI;
return $a;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment