I am new to iOS development. My objective is to show a compass on Screen. I have a latitude and longitude of a certain location. I have gotten my current latitude and longitude by using CLLocation.
I have calculated the distance between two points using an API, but now I开发者_如何学C want to know the correct direction of my phone N/S/E/W and something like according to correct north pole... I am not sure.
Is there some concept of iPhone north pole and actual north pole?
I want show a line pointing towards the particular longitude and latitude, even if my phone is rotating or moving; the line points towards that point only.
Please help me, where i should proceed now? Any guidance or links/tut will be great.
This is called the "heading" of a CLLocation.
See the CLLocationManager doc part to configure heading for you app and call startUpdatingHeading
to be notified with your heading changes, namely when your iPhone is pointing toward another point.
Then use the standard CLLocationManagerDelegate
methods to be informed of heading changes and redraw your line accordingly.
Read the Location Awareness Programming Guide for more info about Location Services and heading, especially this part that even contains sample code.
PS: About the two different north, there is no concept of "iPhone North Pole", that's nothing related the the iPhone itself. In Geographic systems, there are two north references to consider: the Magnetic North Pole, which is defined according to the earth magnetic field, and the True North Pole, which is defined according the rotational axis of the earth.
That's also explained in details in the Location Awareness Programming Guide too (like quite everything; always read Programming Guides which are great and very complete resources in general):
Heading values can be reported relative either to magnetic north or true north on the map. Magnetic north represents the point on the Earth’s surface from which the planet’s magnetic field emanates. This location is not the same as the North Pole, which represents true north. Depending on the location of the device, magnetic north may be good enough for many purposes, but the closer to the poles you get, the less useful this value becomes.
精彩评论