Book Image

Phonegap Essentials

By : Ivan Turkovic
Book Image

Phonegap Essentials

By: Ivan Turkovic

Overview of this book

Table of Contents (15 chapters)

The Device Motion plugin


The Device plugin provides access to information about the device's accelerometer data. The accelerometer is a motion sensor that detects the change (delta) in movement relative to the current device orientation, in three dimensions along the x, y, and z axes.

Device Motion plugin is capturing accelerometer data at a specific snapshot in time. Values for the x, y, and z axes are expressed in m/s^2 and include the effect of gravity (9.81 m/s^2). For example, when the device is lying on top of the table and facing up, the x and y values are 0 and the z value is returning 9.81.

To install the plugin you need to run the following command:

phonegap plugin add cordova-plugin-device-motion

The Device Motion plugin has a few methods that return accelerometer data based on a real-time data representation of the sensor when we call these methods. The plugin provides access to methods through a global navigator.accelerometer object that is available after the deviceready event...