Gyroscope

Improve this doc

$ ionic plugin add cordova-plugin-gyroscope
$ npm install --save @ionic-native/gyroscope

Repo: https://github.com/NeoLSN/cordova-plugin-gyroscope

Read Gyroscope sensor data

Supported platforms

Usage

import { Gyroscope, GyroscopeOrientation, GyroscopeOptions } from '@ionic-native/gyroscope';


constructor(private gyroscope: Gyroscope) { }

...


let options: GyroscopeOptions = {
   frequency: 1000
};

this.gyroscope.getCurrent(options)
  .then((orientation: GyroscopeOrientation) => {
     console.log(orientation.x, orientation.y, orientation.z, orientation.timestamp);
   })
  .catch()


this.gyroscope.watch()
   .subscribe((orientation: GyroscopeOrientation) => {
      console.log(orientation.x, orientation.y, orientation.z, orientation.timestamp);
   });

Instance Members

watch(options)

Watching for gyroscope sensor changes

Param Type Details
options GyroscopeOptions

Optional

Returns: Observable<GyroscopeOrientation> Returns an Observable that resolves GyroscopeOrientation

getCurrent(options)

Get current data from gyroscope sensor

Param Type Details
options GyroscopeOptions

Optional

Returns: Promise<GyroscopeOrientation> Returns a promise that resolves GyroscopeOrientation

GyroscopeOrientation

Param Type Details
x number

Represent x-axis

y number

Represent y-axis

z number

Represent z-axis

timestamp number

Represent timestamp of sensor read. Default is 10000ms

GyroscopeOptions

Param Type Details
frequency number

Represent how often (in milliseconds) sensor should be read. Default is 10000 ms

API

Native

General