gpt4 book ai didi

HTML 5 移动设备方向 API : Alpha (compass) value does not indicate north

转载 作者:太空宇宙 更新时间:2023-11-04 14:21:31 26 4
gpt4 key购买 nike

以下代码片段中的 alpha 值应根据设备的旋转在 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,然后在这些值之间变化。

因为它应该跟随风向,我正试图找出北方在哪里,我需要它以绝对方式而不是相对方式来做到这一点。又名:无论何时何地加载页面时设备面对的方向如何,面向某处时始终显示相同的值。

这些资源表明 API 应该能够做到这一点:

html5rocks

还有这个:

W3C

下面是一个示例,其中“方向”在面向北方时应为 0(或至少返回一致的值):

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

这是指示设备所面对风向的正确方法吗?我需要将其与 Google Maps Api 结合使用。

最后我知道有适用于 Ipad 3 的指南针应用程序,因此该设备应该能够执行此操作。

我很困惑:)

最佳答案

根据 W3C:

Implementations that are unable to provide absolute values for the three angles may instead provide values relative to some arbitrary orientation, as this may still be of utility. In this case, the absolute property must be set to false. Otherwise, the absolute property must be set to true.

关于HTML 5 移动设备方向 API : Alpha (compass) value does not indicate north,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10724707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com