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); ...