Chapter 10. Positioning: accelerometers, location, and the compass
This chapter covers
- Sensing gravity
- Gauging movement
- Determining location and orientation
- Using Core Location
When we first introduced the iPhone and iPad, we highlighted a number of its unique features. Among them were three components that allow the device to figure out precisely where it is in space: a trio of accelerometers, which give it the ability to sense motion in three dimensions; a locational device (using either GPS or faux GPS), which lets it figure out where in the world it is; and a compass to figure out which direction it’s facing.
Other than accessing some basic orientation information, we haven’t done much with these features. We’ll now dive into these positioning technologies and examine how to use them in your programming.
We’ll start with some new ways to look at orientation data and then explain how to use the accelerometers, compass, and GPS in real applications.
The easiest use of the accelerometers is to determine the device’s current orientation. You already used the view controller’s interfaceOrientation property, back in chapter 5. As we mentioned at the time, you can also access orientation information through the UIDevice object. It can provide more information and real-time access that isn’t available using the view controller.