English 中文(简体)
HTML 5 移动设备方向API: Alpha (包) 值未表示北
原标题:HTML 5 Mobile Device Orientation API: Alpha (compass) value does not indicate north

下列代码片段中的阿尔法值应该根据设备的旋转在 0 到 360 之间变换 :

window.addEventListener( deviceorientation , function(eventData) {
    var LR = eventData.gamma;
    var FB = eventData.beta;
    var DIR = eventData.alpha;

    deviceOrientationHandler(LR, FB, DIR);
});

这种变异应该取决于它面对的风向。要做到这一点,设备使用磁强计/指南针。

当我在ipad 3上测试这个时,我遇到了以下的问题:

它从 0 到 360 不等, 但以相对的方式。 页面在装入时显示 0, 然后在 0 到 360 之间变化。 但是, 当设备旋转和页面刷新时, 它会从显示 0 开始, 然后在这些值之间变化 。

它应该遵循风向,而我正试图找出 北方需要它做什么, 而不是以相对的方式 。 AKA: 当它面对某个地方时, 无论何时何地, 当页面加载时, 设备正朝哪个方向, 总是显示相同的值 。

这些冲浪表明,API应有能力做到:

"http://www.html5rocks.com/en/tutorics/ device/方向/" rel="nofollow" >html5rocks

而这一个:

W3C

这里举一个例子,“方向”在面对北面时应该是0(或至少返回一个一致值):

the html5rocks page contains an example (ctrl + f and "try it out"). Can t post more then 2 URLS

这是正确的方式 表示风向 设备正面对的风向吗? 我需要结合谷歌地图Api使用这个方法。

最后我知道Ipad 3 有指南针应用程序 所以这个装置应该能做这个

我感到困惑:

最佳回答

W3C指出:

无法为这三个角度提供绝对值的执行,可能提供与某些任意取向相对的价值,因为这仍然有用,在这种情况下,绝对财产必须被设定为虚假,否则,绝对财产必须设定为真实。

问题回答

With Mobile Safari (iOS), alpha is based on the direction the device was pointing when device orientation was first requested. So when you activate deviceorientation listener while your iPad is showing East, then alpha is 0 at East. To get correct compass direction you need to use the webkit parameter webkitCompassHeading on iOS. All other browsers accept alpha as compass direction. To support them all:

var compassdir;
if(eventData.webkitCompassHeading) {
  compassdir = eventData.webkitCompassHeading;
}
else compassdir = eventData.alpha;

这是一个老问题,但由于过去几年中的一些变化(浏览更新),我也有同样的问题。

<强度 > 设计方向绝对

https:// developmenters.google.com/web/ updates/2016/03/device-disign-changes" rel=“没有跟随 nofollown noreferrer>>https://developers.google.com/web/ updates/2016/03/device-directive-changes

(歌剧作品,铬, 最大松和机器人)

< 加校准 < 坚固 > 设计方向

使用设备运动或使用 HTML5 监视移动来检查罗盘向北





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签