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
: This reads the current compass heading through a handlercompass.watchHeading
: This reads the compass heading at a specific time interval through a handler and returns a reference to itcompass.clearWatch
: This stops a previously defined time interval reading handler
The getCurrentHeading
and watchHeading
functions accept very similar arguments; the only difference is the last argument of the watchHeading...