See how Capacitor fits into the entire Ionic Ecosystem ->
Capacitor is part of the Ionic Ecosystem ->

Motion

Motion APIは、加速度計とデバイスの向きを追跡します(compass heading, etc.)。

Permissions

This plugin is currently implemented using Web APIs. Most browsers require permission before using this API. To request permission, prompt the user for permission on any user-initiated action (such as a button click):

myButton.addEventListener('click', async () => {
  try {
    await DeviceMotionEvent.requestPermission();
  } catch (e) {
    // Handle error
    return;
  }

  // Once the user approves, can start listening:
  const { Motion } = Capacitor.Plugins;
  Capacitor.Plugins.Motion.addListener('accel', (event) => {
  });
});

Example

const { Motion } = Capacitor.Plugins;
Motion.addListener('accel', (event) => {
});

See the DeviceMotionEvent API to understand the data supplied in event.

API

Contributors

BackNext