Device Orientation
Requires Cordova plugin: cordova-plugin-device-orientation
. For more info, please see the Device Orientation docs.
联系我们?
If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic's experts offer official maintenance, support, and integration help.
Ionic 加速度 Device Orientation插件的安装(Installation)
Ionic EE comes with fully supported and maintained plugins from the Ionic Team. Learn More or Contact Us
Ionic 加速度 Device Orientation插件支持的平台(Supported Platforms)
- Amazon Fire OS
- Android
- BlackBerry 10
- Browser
- Firefox OS
- iOS
- Tizen
- Ubuntu
- Windows
- Windows Phone
Ionic 加速度 Device Orientation插件的用法(Usage)
// DeviceOrientationCompassHeading is an interface for compass
import { DeviceOrientation, DeviceOrientationCompassHeading } from '@ionic-native/device-orientation/ngx';
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();