Device Motion

Contents

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

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

Stuck on a Cordova issue?

Installation

Community Enterprise
ionic cordova plugin add cordova-plugin-device-motion npm install @ionic-native/device-motion
Ionic EE comes with fully supported and maintained plugins from the Ionic Team. Learn More   or   Contact Us
ionic activate-native-ee --key=YOURPRODUCTKEY ionic integrations add @ionic-native/device-motion

Usage

import { DeviceMotion, DeviceMotionAccelerationData } from '@ionic-native/device-motion/ngx';

constructor(private deviceMotion: DeviceMotion) { }

...

// Get the device current acceleration
this.deviceMotion.getCurrentAcceleration().then(
  (acceleration: DeviceMotionAccelerationData) => console.log(acceleration),
  (error: any) => console.log(error)
);

// Watch device acceleration
var subscription = this.deviceMotion.watchAcceleration().subscribe((acceleration: DeviceMotionAccelerationData) => {
  console.log(acceleration);
});

// Stop watch
subscription.unsubscribe();