首页 > 解决方案 > 在“地理位置”中设置时,enableHighAccuracy 是否应该有所作为?

问题描述

这是我的代码:

  async getGridPointApiUrl() {
    const position = await this.getPosition();
    let latitude = position.coords.latitude;
    let longitude = position.coords.longitude;
    console.log([latitude, longitude, position.coords.accuracy]);
  }

  getPosition() {
    return new Promise((resolve, reject) => {
      navigator.geolocation.getCurrentPosition(
        resolve,
        reject,
        {
          maximumAge: 0,
          timeout: Infinity,
          enableHighAccuracy: true
        });
    });
  }

当我运行这个时,我得到了 5 米的精度。没有办法是对的!返回的坐标相距 10 英里。虽然,无论enableHighAccuracy是真还是假,我都会得到相同的结果。假设会发生这种情况吗?我在基于 Chromium 的Brave Browser上对此进行了测试。

我决定在 Firefox 上检查相同的代码,等等,返回的坐标要好得多,而且准确度读数似乎正确。但是,布尔值enableHighAccuracy同样对 Firefox 中显示的准确性没有影响。

我在这里错过了什么吗?有没有办法让 Brave 的准确性至少和 Firefox 一样好?

标签: javascriptreactjsgeolocation

解决方案


推荐阅读