【发布时间】:2011-08-25 09:50:00
【问题描述】:
我有以下代码来检查 HTML 5 中的设备方向和设备运动处理。我从http://dev.w3.org/geo/api/spec-source-orientation.html 得到这个。我使用 iPhone3G 测试了我的代码,并且运动事件被捕获。我不知道为什么设备方向没有被困住。我相信由于 iPhone3G 没有 Compass 支持,我无法捕获 'compassneedcalibration' 事件。
我在 Android 浏览器中测试了该应用程序。 (HTC 野火)。我无法得到任何事件。请分享您为什么我们无法在 Android Mobile 中收到事件?
window.addEventListener("compassneedscalibration", function(event) {
alert('Your compass needs calibrating! Wave your device in a figure-eight motion');
event.preventDefault();
}, true);
window.addEventListener("deviceorientation", function(event) {
// process event.alpha, event.beta and event.gamma
alert("deviceorientation");
}, true);
window.addEventListener("devicemotion", function(event) {
// Process event.acceleration, event.accelerationIncludingGravity,
// event.rotationRate and event.interval
alert("devicemotion");
}, true);
更新 1
我在 iPhone 和 iPad 中进行测试时注意到的一件事是,无论设备是否移动,事件都会持续不断地触发。
更新 2
我找到了我在 UPDATE 1 中提出问题的原因。该 API 似乎每秒检测并提供 50 次加速度计数据。
【问题讨论】:
标签: javascript iphone android ipad html