地理位置标题API实际未测量标题吗?

问题描述 投票:0回答:1

我正在尝试衡量用户的航向,并使用数据来旋转我制作的指南针图像。这将导致图像不断指向北,因此当用户移动手机时,图像也会随之移动。但是,航向值完全依靠自身大量跳跃,就像我放下手机一样,航向也大量移动。我在手机上下载了一个指南针应用程序(这就是我正在测试的应用程序),并且指南针很好。

这是我放入HTML的方式

<div id="compass">
  <img id="compassIMG" src="Morgsimages/compassIcon.png">
</div>
<div id="compassInfo"></div>

这是我的JavaScript

navigator.geolocation.watchPosition(position => {
        let heading = position.coords.heading;
        var compass = document.getElementById('compass');
        var info = document.getElementById('compassInfo');

        info.textContent = 'Heading: '+heading;
        compass.style.transform = `rotate(${heading}deg)`
javascript html geolocation
1个回答
0
投票

不幸的是,它取决于设备,coords.heading。如果此信息不可用,它将返回null。

根据https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates/heading,“如果设备无法提供标题信息,则该值为空。”

© www.soinside.com 2019 - 2024. All rights reserved.