Hi,
I'm using this code to figure out the bearing between 2 points:
function calcBearing($lat1, $lon1, $lat2, $lon2){
$lat1 = deg2rad($lat1);
$lat2 = deg2rad($lat2);
$dLon = deg2rad($lon2) - deg2rad($lon1);
$y = sin($dLon) * cos($lat2);
$x = cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($dLon);
return atan2($y, $x);
}
echo calcBearing(38.6733111, -77.0258, 38.695425, -76.8723667) . "<br>\n";
It returns:
1.38737965387
But the answer should be (or closer to):
1.3881099876
Not a huge difference at first glance, but when using 1.38737965387 to plot a new point between the 2 points passed in it's off by about 10 feet.
Where is the error coming from? Is there a better formula to use to avoid these errors.
Thanks,
Metzen