简体   繁体   English

是否可以使用Javascript访问iPhone加速度计?

[英]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. 我开始尝试为我的iPhone以及我的朋友拥有的其他支持网络的手机做一些基于网络的游戏编程,并且很难在浏览器中查找使用Javascript访问加速度计的信息。

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? 或者,这也适用于Android手机吗?

In the latest iOS update (4.2) the accelorometer is now accessible from Javascript. 在最新的iOS更新(4.2)中,现在可以从Javascript访问accelorometer。

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

iOS 4.2 provides Accelerometer & Gyroscope support through the DeviceOrientation API. iOS 4.2通过DeviceOrientation API提供Accelerometer和Gyroscope支持。

Here a working javascript snippet. 是一个有效的JavaScript代码段。

如果您使用的是iOS 4.2或更高版本,那么您可以这样做: http//www.albertosarullo.com/blog/javascript-accelerometer-demo-source

jharlap is correct, however I'd be curious to know if this would work on the Palm Pre. jharlap是正确的,但我很想知道这是否适用于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. Pre上的原生开发是使用html和JavaScript完成的,但是有一些特殊的JavaScript API可以访问我认为仅适用于本地存储应用程序的手机功能。 I wonder if these are available through the browser. 我想知道这些是否可以通过浏览器获得。 I doubt it, but it would be interesting. 我对此表示怀疑,但这会很有趣。

Checkout PhoneGap project . 结帐PhoneGap项目 It provides API to access the accelerometer and the GPS location from javascript. 它提供了从javascript访问加速度计和GPS位置的API。

"Regular" javascript cannot access the accelerometer info, it can access the geolocation using the W3C geolocation API supported by iPhone OS 3.0. “常规”javascript无法访问加速度计信息,它可以使用iPhone OS 3.0支持的W3C地理定位API访问地理位置。

Yet, a project (eg PhoneGap) can be used to build a bridge between javascript and Objective-C capabilities to expose that functionality. 然而,一个项目(例如PhoneGap)可用于在javascript和Objective-C功能之间建立桥梁以公开该功能。 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. 如果您要将应用程序部署为独立应用程序,只需要一个从服务器加载html内容的WebKit,这就有效。

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. 我没有使用他们的框架,但是他们为iPhone和Android项目提供了模板,你可以开发你的javascript游戏,它几乎可以在iPhone和Android上开箱即用。 I cannot comment on the performance and the user experience though. 我不能评论性能和用户体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM