O'Reilly logo

Beginning PhoneGap by Thomas Myer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7

Compass

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • Getting to know the compass
  • Using Compass methods
  • Using the Compass options

In Chapter 6, you learned how to use the accelerometer. In this chapter, you learn how to use a device’s built-in compass.

GETTING TO KNOW THE COMPASS

In this section, you learn what the compass is, and how you can use it.

What Is the Compass?

Simply put, the compass built into your device obtains the direction in which the device is pointing. Ideally, if you’re running the PhoneGap Compass API, whichever direction you turn the device, you’ll get back a heading (a number between 0 and 359.99) that corresponds to the direction in which you’re pointing.

Specifically, your device has a solid-state or digital compass. It uses two or three (depending on the model of your device) magnetic field sensors to supply data back to your device. The device uses this data to provide a correct heading with some rapid trigonometric calculations.

If your device is any of the following, it also contains a magnetometer:

  • HTC HD2
  • HTC Dream
  • HTC Desire HD
  • HTC Evo
  • HTC Wildfire
  • Apple
  • Sony Ericsson Xperia X8
  • Sony Ericsson Xperia X10
  • iPhone 4
  • Motorola Droid[4]
  • Motorola Quench
  • Motorola Atrix 4g
  • Nokia N97
  • Nokia E72
  • Nokia N8
  • Blackberry Torch
  • Samsung Galaxy S
  • Samsung Nexus One
  • Samsung Nexus S

A magnetometer can measure the strength and/or direction of a magnetic field, produced either by a machine or in nature. This chapter does not go into detail about magnetometers.

Differences ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required