The location manager and its delegate can deliver our heading as well as our location.
Heading is the direction that we’re facing. It can be measured with respect to magnetic north or true north. In Manhattan, the compass needle points about 13° to the left of true north; I looked it up here. This 13° difference is called the magnetic declination. The avenues point 29° to the right of true north; I looked it up here. The needle therefore points about 42° to the left of the avenues. Do not follow a compass needle when trying to walk uptown.
The instance variable
magneticNorth
contains the direction in which the top of the iPhone is pointing,
measured in degrees to the right of magnetic north:
0° for north,
90° for east,
180° for south, etc.
We use the top of the iPhone because
we set the
headingOrientation
property of the
location
manager
to
CLDeviceOrientationPortrait
.
The variable theta (θ) is measured in radians to the left of east: 0 radians for east, π/2 radians for north, π radians for west.
main.m
HeadingAppDelegate
View
Heading-Info.plist
Add the Core Location framework to the project
as we did
here.
Add the
UIRequiredDeviceCapabilities
key to the
Heading-Info.plist
magnetomter
.
locationServicesEnabled
variable of class
LLocationManager
.
x
and
y
instance variables,
which are magnitudes measured in
microteslas.
Ignore
z
.