Using the accelerometer
With iOS version 4.2 and newer it is now possible to read accelerometer and gyroscope data via javascript. Here’s an example, what could be done with it: http://isthisanearthquake.com/
To read the data from the accelerometer use the following javascript event:
window.ondevicemotion = function(event) {
// event.accelerationIncludingGravity.x
// event.accelerationIncludingGravity.y
// event.accelerationIncludingGravity.z
}
If you want to read the data from the gyroscope (iPhone 4, iPod Touch 4G+ and iPad 2 only):
window.ondeviceorientation = function(event) {
// event.alpha
// event.beta
// event.gamma
}
For more information visit: http://www.mobilexweb.com/blog/safari-ios-accelerometer-websockets-html5
Shake Event
If you need to create a shake event (for example to fetch some data when shaking the device) take a look at http://www.jeffreyharrell.com/blog/2010/11/creating-a-shake-event-in-mobile-safari/


Leave a comment, suggestion or question.