Using the Accelerometer with PhoneGap


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var latest = null;
  2.  
  3. function doDeviceReady()
  4. {
  5. var options = {
  6. frequency: FREQUENCY_ACCEL
  7. };
  8.  
  9. watchID = navigator.accelerometer.watchAcceleration(
  10. doAcceleration,
  11. doError,
  12. options
  13. );
  14. }
  15.  
  16. function doAcceleration( acceleration )
  17. {
  18. latest = {
  19. x: acceleration.x,
  20. y: acceleration.y
  21. };
  22. }
  23.  
  24. function doError()
  25. {
  26. alert( 'Acceleration Error' );
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.