compute true north based on successive user location
I'm working on an app that should include a compass (it should work on iphone 3G also). however as there is no a compass on iphone 3G i'm looking for a way to know the true north orientation based on the CLLocation returned by the iPhone.
Note: the app should give as 开发者_如何学运维accurate as possible value even if the phone is using "cell towers" to know the actual position (not very accurate).
thanks in advance.
You can approximate the users heading assuming they have been moving in a straight line between gps updates.
I would first set the desired accuracy to the highest. You will need it since a small change in position will result in a large change in angle.
Now call the coordinate of the first location L1
, and the coordinate of the next location L2
.
Your heading vector , h
= L2 - L1
now if h = (lon, lat)
To get the heading you need use some trig:
x = arctan ( lon / lat )
I would consider taking averages / smoothing the result somehow.
精彩评论