Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there access to the iPhone accelerometer using Javascript?

I'm starting to try and do some web based game programming for my iPhone, and other web enabled phones that my friends have, and was having a hard time finding information on accessing the accelerometer using Javascript in the browser.

With the latest release, I know I've got access to location information now but I was hoping that I could make use of the accelerometer for some of the games I plan on making.

Alternately, is this also possible with the Android phones?

like image 970
ahanson Avatar asked Aug 13 '09 19:08

ahanson


People also ask

How do I test the accelerometer on my iPhone?

Tap Receiver to check the audio, Vibration to try the vibrating feature, or Sensor to test the accelerometer and other sensors. You can also tap Touch and then move your finger around the screen to test the touch screen, or tap Low Frequency to test low-frequency sounds.

What can you do with accelerometer data?

Accelerometers can be used to measure vibration on cars, machines, buildings, process control systems and safety installations. They can also be used to measure seismic activity, inclination, machine vibration, dynamic distance and speed with or without the influence of gravity.

How does the iPhone accelerometer work?

When the phone accelerates in a particular direction, some of these springs will get compressed in order to make the tiny test mass also accelerate. The accelerometer measures this spring compression and uses that to determine the acceleration of the phone. With that, it will know if it is facing up or down.

How accurate is iPhone accelerometer?

Yes, the iPhone accelerometer is calibrated and has an error under 1% in your case. If you collect measurements from other (hundreds of) users, you could calculate the mean error of the device (I guess it's about 1% though). The sensor is only calibrated ~1% error for each axis.


2 Answers

In the latest iOS update (4.2) the accelorometer is now accessible from Javascript.

See: http://www.mobilexweb.com/blog/safari-ios-accelerometer-websockets-html5

like image 193
Olly Avatar answered Sep 17 '22 18:09

Olly


iOS 4.2 provides Accelerometer & Gyroscope support through the DeviceOrientation API.

Here a working javascript snippet.

like image 40
systempuntoout Avatar answered Sep 20 '22 18:09

systempuntoout