O'Reilly logo

PhoneGap Essentials by Ivan Turkovic

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

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

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