Created
June 1, 2012 10:04
-
-
Save abarth500/2850913 to your computer and use it in GitHub Desktop.
Direction of two points
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
<?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