Device Orientation

Improve this doc

$ ionic plugin add cordova-plugin-device-orientation

Repo: https://github.com/apache/cordova-plugin-device-orientation

Requires Cordova plugin: cordova-plugin-device-orientation. For more info, please see the Device Orientation docs.

Usage

// CompassHeading is an interface for compass
import { DeviceOrientation, CompassHeading } from 'ionic-native';


// Get the device current compass heading
DeviceOrientation.getCurrentHeading().then(
  (data: CompassHeading) => console.log(data),
  (error: any) => console.log(error)
);

// Watch the device compass heading change
var subscription = DeviceOrientation.watchHeading().subscribe(
  (data: CompassHeading) => console.log(data)
);

// Stop watching heading change
subscription.unsubscribe();

Static Members

getCurrentHeading()

Get the current compass heading.

Returns: Promise<DeviceOrientationCompassHeading>

watchHeading(options)

Get the device current heading at a regular interval

Stop the watch by unsubscribing from the observable

Param Type Details
options DeviceOrientationCompassOptions

Options for compass. Frequency and Filter. Optional

Returns: Observable<DeviceOrientationCompassHeading> Returns an observable that contains the compass heading

DeviceOrientationCompassOptions

Param Type Details
frequency
(optional)
number

How often to retrieve the compass heading in milliseconds. (Number) (Default: 100)

filter
(optional)
number

The change in degrees required to initiate a watchHeading success callback. When this value is set, frequency is ignored. (Number)

DeviceOrientationCompassHeading

Param Type Details
magneticHeading number

The heading in degrees from 0-359.99 at a single moment in time. (Number)

trueHeading number

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 number

The deviation in degrees between the reported heading and the true heading. (Number)

timestamp any

The time at which this heading was determined. (DOMTimeStamp)

API

Native

General