Device Orientation

Contents

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

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

Ionic 加速度 Device Orientation插件的安装(Installation)

ionic cordova plugin add cordova-plugin-device-orientation npm install @ionic-native/device-orientation

Ionic 加速度 Device Orientation插件的用法(Usage)

// DeviceOrientationCompassHeading is an interface for compass
import { DeviceOrientation, DeviceOrientationCompassHeading } from '@ionic-native/device-orientation';

constructor(private deviceOrientation: DeviceOrientation) { }

...

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

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

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