Device Orientation
Requires Cordova plugin: cordova-plugin-device-orientation
. For more info, please see the Device Orientation docs.
https://github.com/apache/cordova-plugin-device-orientation
Stuck on a Cordova issue?
If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic’s experts offer premium advisory services for both community plugins and premier plugins.
Installation#
- Capacitor
- Cordova
- Enterprise
$ npm install cordova-plugin-device-orientation $ npm install @ionic-native/device-orientation $ ionic cap sync
$ ionic cordova plugin add cordova-plugin-device-orientation $ npm install @ionic-native/device-orientation
Ionic Enterprise comes with fully supported and maintained plugins from the Ionic Team. Learn More or if you're interested in an enterprise version of this plugin Contact Us
#
Supported Platforms- Amazon Fire OS
- Android
- BlackBerry 10
- Browser
- Firefox OS
- iOS
- Tizen
- Ubuntu
- Windows
- Windows Phone
#
Usage#
ReactLearn more about using Ionic Native components in React
#
Angular// DeviceOrientationCompassHeading is an interface for compassimport { DeviceOrientation, DeviceOrientationCompassHeading } from '@ionic-native/device-orientation/ngx';
constructor(private deviceOrientation: DeviceOrientation) { }
...
// Get the device current compass headingthis.deviceOrientation.getCurrentHeading().then( (data: DeviceOrientationCompassHeading) => console.log(data), (error: any) => console.log(error));
// Watch the device compass heading changevar subscription = this.deviceOrientation.watchHeading().subscribe( (data: DeviceOrientationCompassHeading) => console.log(data));
// Stop watching heading changesubscription.unsubscribe();