O'Reilly logo

PhoneGap 3 Beginner's Guide by Giorgio Natili

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

Compass

The PhoneGap Compass API allows you to obtain the direction that the device is pointing to. The compass is a sensor that detects the direction or heading in which the device is pointed and returns the heading of the device in degrees using values from 0 to 359.99. The Compass API works similarly to the Accelerometer API; in fact you can read the current device heading or you can define a watcher in order to continuously read the heading value.

The Compass API is available on the compass property of the navigator object and exposes the following functions:

  • compass.getCurrentHeading, reads the current compass heading through a handler.
  • compass.watchHeading, reads the compass heading at a specific time interval through a handler and returns ...

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