Hi,
Goal: I'm trying to have my Ardunio with its GPS shield on, compute the bearing (angle on a "circle") between GPS point A (my location), and GPS B (destination).
Problem: The forumla I am using for this when computed on the website which gives it, will give me a different angle (bearing) than that which is computed when when I take the formula and use it on my Arduino.
I'm using a well-recommended webpage for the equation to compute this (see under 'Bearing', 'forumla':
http://www.movable-type.co.uk/scripts/latlong.html
Here are the GPS locations I'm using:
GPS A: 38.900890, -77.049041
GPS B: 38.889469, -77.035324
Here is the formula when put on the Arduino:
GPS_heading = (180 / M_PI) * (atan2(sin(GPS_B_long - GPS_A_long)*cos(GPS_B_lat), cos(GPS_A_lat)*sin(GPS_B_lat) - sin(GPS_A_lat)*cos(GPS_B_lat)*cos(GPS_B_long - GPS_A_long)));
GPS_heading = ((int)GPS_heading + 360) % 360;
For the above website and Arduino code, here are the differences in the bearing between the GPS locations:
Website calculated: 136 degrees
(Note: GPS A (Point 1) and GPS B (Point 2) coordinates are plugged into top box, "Great-circle distance between two points", and the "Initial Bearing" output is given next to it, which is 136 degrees for this example.)
Arduino calculated: 155 degrees
I'm not sure if I've programmed the formula correctly, or if there is some other thing in my code I've overlooked, but I think I should first start with the formula.
Note: The bearing differences will vary depending on the GPS A point (when GPS B is used as a reference), so I cannot scale it (other times it's off only by 1 degree when using the same GPS B location, and GPS A is taken at random location about a similar distance to GPS B).
Any ideas?