0

I got the azimuth of a point, the compass heading and an api which can set an arrow to a certain direction (0 is top, 90 is right, 180 is bottom, 360 is top)

how i calculate the correct value for the arrow if i want it to point to the point which i took the azimuth form?

thank you

blab
  • 1
  • 1
  • 1
  • I don't understand your question :( – Ichibann May 16 '11 at 11:38
  • A point doesn't have an azimuth, the vector between two points does. A compass heading is effectively an azimuth. The directions in the OP are those used for navigation (e.g. by surveyors and cartographers), they have a different zero and direction of rotation to mathematic angles. When you formulate a real question, you can be helped with that. – RobG May 16 '11 at 11:48
  • sorry, let me try again: i got the latitude and longitude of two points, my current location and a target location. what i also got is the compass heading. so how do i calculate in which direction the target location is? – blab May 16 '11 at 11:52

2 Answers2

4

The formula for heading between two lat/long coords is:

=atan2(cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1), sin(lon2-lon1)*cos(lat2))

where lat2/lon2 is your end point, lat1/lon1 is your start point.

Your answer will be between -pi and pi radians.

To get the heading in degrees, convert your radians to degrees then do: (degrees+360)%360 = heading. The heading will then be 0 for north, 90 for east etc.

The compass heading means nothing, unless you need to adjust your heading from true north to magnetic north.

Myforwik
  • 3,438
  • 5
  • 35
  • 42
0

iPhone Compass GPS Direction

Community
  • 1
  • 1
Keir Finlow-Bates
  • 993
  • 2
  • 14
  • 27