The PhoneGap Accelerometer API allows you to detect the device movement change values relative to device orientation. Keep in mind that the accelerometer detects the values as a delta movement relative to the current device position. Even more important, it takes into consideration the effect of gravity (i.e., 9.81 m/s^2), so that, when a device is lying flat on a table facing up, the value returned should be x = 0, y = 0, and z = 9.81.
You can detect the device acceleration data using the method getCurrentAcceleration
or setting up a watcher through the method watchAcceleration
. Both methods are available on the navigator.accelerometer
object and accept similar arguments.
The getCurrentAcceleration
method accepts a success and a failure callback function as argument and doesn't return anything. The watchAcceleration
method accepts an additional argument in order to define the options and return a reference to the current watcher.
In order to constantly watch the acceleration...