Adjusting the accelerometer sensor update interval
The getCurrentAcceleration
method obtains data from the accelerometer at the time it was called - a single call to obtain a single response object. In this recipe, we'll build an application that allows us to set an interval to obtain a constant update from the accelerometer to detect continual movement from the device.
How to do it…
We will provide additional parameters to a new method available through the PhoneGap API to set the update interval:
- First, create a new PhoneGap project named
accelupdate
. Open Terminal or Command Prompt and run the following command:phonegap create accelupdate com.myapp.accelupdate accelupate
- Add the devices platform. You can choose to use Android, iOS, or both:
cordova platform add ios cordova platform add android
- Add the
device-motion
plugin by running the following command:phonegap plugin add org.apache.cordova.device-motion
- Open
www/index.html
and clean up unnecessary elements; so you have the...