I am new to objective-c so I want to apologize if my question is too rubbish.
I am programming a compass and yet, it is working (thanks to a tutorial). Actual position (Longitude and Lattitude) is given. Is it possible that my arrow within the compass can show me the direction to a specific location (longitude2 and lattitude2)? I have read that I have to consider the magnetic and the true heading of the iphone.
thanks and sry for my delated answer. I am working on an arrow showing to a specific direction. What I did now is, getting this arrow doing an animation but my problem is, that it should (at first) point to the same direction like the iphone is "heading".
My code so far:
I have other routines to get the latitude, longitude and labels showing me the heading and it works. My arrow spins around madly without any reason. I want the arrow points on the same direction like the trueHeading. That means in the way the iPhone
From the CLLocation-Bearing project by tadeldv: https://github.com/tadelv/CLLocation-Bearing
this gives you the angel between north pole and your target. then you have to add/subtract the angle of your current heading.
Good links to calculate the bearing:
If you don't need it to be too accurate, then it is fairly easy. All you need to do is calculate the angle between the 2 points, and show the angle on the compass. (As you haven't posted code, I'm not sure if you have a method like
setAngleForCompass
, but you should!) Try this:Alternatively, you could use the CMMotionManager to get access to the gyroscope, which will also point you in the right direction. (pun intended!) Hope that Helps!
I also needed to calculate heading to a location. The best method I found was to use the Spherical Law of Cosines. I created C functions to implement this and they are available Here on github. Sounds like you need the headingInDegrees function. This will give you a true heading.