Chapter 4. Digital Compass
The digital compass functionality on the iPhone and iPad is provided by a magnetometer. The magnetometer measures the strength of the magnetic field surrounding the device. However, in the absence of any strong local fields, these measurements will be of the ambient magnetic field of the Earth, allowing the device to determine its “heading” with respect to the geomagnetic North Pole and act as a digital compass. The geomagnetic heading and true heading, relative to the geographical North Pole, can vary widely (by several tens of degrees depending on your location).
About the Magnetometer
The magnetometer will return the heading (or yaw) of the device (see Figure 4-1).

Figure 4-1. Using the magnetometer to determine the heading (yaw) of the device
Along with reporting the current location, the CLLocationManager class can report the current
heading of the device, in the case where the device’s hardware supports
it. If location updates are also enabled, the location manager returns
both true heading and magnetic heading values. If location updates are not
enabled, the location manager returns only the magnetic heading
value.
Note
Magnetic heading updates are available even if the user has switched off location updates in the Settings application. Additionally, users are not prompted to give permission to use heading data, as it is assumed that magnetic heading information ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access