views:

1841

answers:

4

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?

+2  A: 

Short and simple answer: no. If you want to access the accelerometer data on an iPhone you'll need to develop a full-blown iPhone app, not just a web app that uses iPhone extensions.

Can't answer about Android, though.

jharlap
A: 

jharlap is correct, however I'd be curious to know if this would work on the Palm Pre. Native development on the Pre is done using html and JavaScript, however there are special JavaScript APIs to access the phone's features that I believe only work for locally stored apps. I wonder if these are available through the browser. I doubt it, but it would be interesting.

Phairoh
A: 

Checkout PhoneGap project. It provides API to access the accelerometer and the GPS location from javascript.

"Regular" javascript cannot access the accelerometer info, it can access the geolocation using the W3C geolocation API supported by iPhone OS 3.0.

Yet, a project (e.g. PhonGap) can be used to build a bridge between javascript and Objective-C capabilities to expose that functionality. This works if you want to deploy the app as a standalone application, that simply has one WebKit which loads the html content from the server.

I haven't played with their framework, but they provide templates for the iPhone and Android projects and you can work on developing your javascript game which would work almost-out-of-the-box on iPhone and Android. I cannot comment on the performance and the user experience though.

notnoop
A: 

I posted the same type question on a blog by someone who was developing with PhoneGap (Micheal Nachbaur I believe) and he was very well versed in what Apple would allow when developing for the iPhone. The answer was no, for reasons mentioned above. It would appear to not be in Apple's interest to expose advanced features to web based pages which would then kind of defeat the need for the Apple App Store. So PhoneGap is a way to create 'apps' but not a way to gain access thru javascript in a web page. Damn....

I'm still looking to see if this can be done on other phones, so we can only hope Android, Palm or someone lets it happen.

Dwight Vietzke