Cordova Version:

Document TOP » API Reference » Core Cordova Plugins » Device Orientation Plugin

Device Orientation Plugin

Tested Version: 1.0.7

Note

This document is based on the original Cordova docs available at Cordova Docs ( GitHub )

This plugin provides access to the device’s compass. The compass is a sensor that detects the direction or heading that the device is pointed, typically from the top of the device. It measures the heading in degrees from 0 to 359.99, where 0 is north.

Access is via a global navigator.compass object. Although the object is attached to the global scoped navigator, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(navigator.compass);
}

Plugin ID

cordova-plugin-device-orientation

Adding the Plugin in Monaca

In order to use this plugin, please enable Device Orientation plugin in Monaca Cloud IDE.

Supported Platforms

  • Android
  • iOS

Methods

  • navigator.compass.getCurrentHeading
  • navigator.compass.watchHeading
  • navigator.compass.clearWatch

CompassHeading

A CompassHeading object is returned to the compassSuccess callback function.

Properties

  • magneticHeading: The heading in degrees from 0-359.99 at a single moment in time. (Number)
  • trueHeading: The heading relative to the geographic North Pole in degrees 0-359.99 at a single moment in time. A negative value indicates that the true heading can’t be determined. (Number)
  • headingAccuracy: The deviation in degrees between the reported heading and the true heading. (Number)
  • timestamp: The time at which this heading was determined. (DOMTimeStamp)

Android Quirks

  • The trueHeading property is not supported, but reports the same value as magneticHeading.
  • The headingAccuracy property is always 0 because there is no difference between the magneticHeading and trueHeading.

iOS Quirks

  • The trueHeading property is only returned for location services enabled via navigator.geolocation.watchLocation().

CompassError

A CompassError object is returned to the compassError callback function when an error occurs.

Properties

  • code: One of the predefined error codes listed below.

Constants

  • CompassError.COMPASS_INTERNAL_ERR
  • CompassError.COMPASS_NOT_SUPPORTED