The Device Orientation plugin
The Device Orientation plugin has access to the device's compass. The compass acts as a sensor that displays the direction or heading that the device is pointed to; usually it is located on the top of the device. The compass sensor measures the heading in degrees from 0 to 359.99 degrees, where 0 denotes north.
To install the plugin, you need to run the following command:
phonegap plugin add cordova-plugin-device-orientation
The Device Orientation plugin provides a global navigator.compass
object that is available only after the deviceready
event is fired, so you need to listen for that event before doing any action or readings with the compass sensor:
document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { console.log(navigator.compass); }
The Device Orientation plugin has the following methods:
navigator.compass.getCurrentHeading
navigator.compass.watchHeading
navigator.compass.clearWatch
With this plugin, you need to...