メインコンテンツまでスキップ
Version: v6

Device Motion

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?

Don't waste precious time on plugin issues.

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

$ npm install cordova-plugin-device-motion 
$ npm install @awesome-cordova-plugins/device-motion
$ ionic cap sync

Supported Platforms

  • Android
  • BlackBerry 10
  • Browser
  • Firefox OS
  • iOS
  • Tizen
  • Ubuntu
  • Windows
  • Windows Phone 8

Usage

React

Learn more about using Ionic Native components in React

Angular

import { DeviceMotion, DeviceMotionAccelerationData } from '@awesome-cordova-plugins/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();