Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angle between 2 GPS Coordinates

I'm working in another iPhone App that uses AR, and I'm creating my own framework, but I'm having trouble trying to get the angle of a second coordinate relative to the current device position, anyone know a good resource that could help me with this?

Thanks in advance!

like image 358
Paulo Ferreira Avatar asked Sep 28 '10 02:09

Paulo Ferreira


People also ask

How do you find the angle between two GPS points?

Here is the formula to find the second point, when first point, bearing and distance is known: latitude of second point = la2 = asin(sin la1 * cos Ad + cos la1 * sin Ad * cos θ), and. longitude of second point = lo2 = lo1 + atan2(sin θ * sin Ad * cos la1 , cos Ad – sin la1 * sin la2)

What is the distance between two GPS coordinates?

For this divide the values of longitude and latitude of both the points by 180/pi. The value of pi is 22/7. The value of 180/pi is approximately 57.29577951. If we want to calculate the distance between two places in miles, use the value 3, 963, which is the radius of Earth.


1 Answers

If the two points are close enough together, and well away from the poles, you can use some simple trig:

float dy = lat2 - lat1;
float dx = cosf(M_PI/180*lat1)*(long2 - long1);
float angle = atan2f(dy, dx);

EDIT: I forgot to mention that latN and longN — and therefore dx and dy — can be in degrees or radians, so long as you don't mix units. angle, however, will always come back in radians. Of course, you can get it back to degrees if you multiply by 180/M_PI.

like image 188
Marcelo Cantos Avatar answered Sep 29 '22 19:09

Marcelo Cantos