Device Motion
$ ionic plugin add cordova-plugin-device-motion
Repo: https://github.com/apache/cordova-plugin-device-motion
Requires Cordova plugin: cordova-plugin-device-motion
. For more info, please see the Device Motion docs.
Usage
import {DeviceMotion} from 'ionic-native';
// Get the device current acceleration
DeviceMotion.getCurrentAcceleration().then(
acceleration => console.log(acceleration),
error => console.log(error)
);
// Watch device acceleration
var subscription = DeviceMotion.watchAcceleration().subscribe(acceleration => {
console.log(acceleration);
});
// Stop watch
subscription.unsubscribe();
Static Methods
getCurrentAcceleration()
Get the current acceleration along the x, y, and z axes.
Returns:
Promise<any>
Returns object with x, y, z, and timestamp properties
watchAcceleration(options)
Watch the device acceleration. Clear the watch by unsubscribing from the observable.
// Watch device acceleration
var subscription = DeviceMotion.watchPosition().subscribe(acceleration => {
console.log(acceleration);
});
// Stop watch
subscription.unsubscribe();
Param | Type | Details |
---|---|---|
options |
Returns:
Observable<accelerationData>