【问题标题】:Geolocation Error in Google ChromeGoogle Chrome 中的地理位置错误
【发布时间】:2017-07-21 20:30:41
【问题描述】:

我知道,this problem 过去已经被举报过。

但在 2015 年就解决了。现在又回到了 2017 年!

错误 (Geolocation Position Error, Code 2) 出现在 Chrome(版本 56.0.2924.87(64 位))中:

https://www.googleapis.com/”的网络位置提供程序:已返回 错误代码 403。

错误代码 2

请注意:Chrome 需要 HTTPS 进行地理位置!

function getCoords() {
  return new Promise(function(resolve, reject) {
    if (navigator.permissions) {
      navigator.permissions.query({
        name: 'geolocation'
      }).then(function(permission) {
        switch (permission.state) {
          case 'granted':
            navigator.geolocation.getCurrentPosition(function(pos) {
              resolve(pos.coords);
            }, function(error) {
              console.error('Error Code: ' + error.code + ' - ' + error.message);
            });
            break;
          case 'prompt':
            console.info('Check Geolocation Promt.');
            navigator.geolocation.getCurrentPosition(function(pos) {
              resolve(pos.coords);
            }, function(error) {
              console.error('Error Code: ' + error.code + ' - ' + error.message);
            });
            break;
          case 'denied':
          default:
            resolve(null);
            break;
        }
      });
    } else {
      reject(new DOMError('NotImplemented', 'Permission API is not supported'));
    }
  });
}

function locate() {
  if (typeof Promise !== "undefined" && Promise.toString().indexOf("[native code]") !== -1) {
    getCoords().then(function(coords) {
      if (coords !== null) {
        console.log(coords);
        document.getElementById('coords').value = coords.latitude + ', ' + coords.longitude;
      } else {
        console.warn('No coords returned :/');
      }
    });
  } else {
    console.warn('This browser doesn\'t support geolocation.');
  }
}
<button onclick="javascript:locate()">Locate me</button>
<input type="text" id="coords" readonly/>

此 Google Maps API 示例中的问题似乎相同:https://developers.google.com/maps/documentation/javascript/examples/map-geolocation

【问题讨论】:

标签: google-maps google-chrome geolocation


【解决方案1】:

据我所知,此错误与域证书有关,在 Chrome 中,它仅适用于以“Https”开头的 URL,而不是“http”。

如果您将浏览器从 Chrome 更改为 Edge 或其他,则不会出现此错误。

【讨论】:

    【解决方案2】:

    我知道该主题包含谷歌浏览器,但出现此错误:

    Network location provider at 'https://www.googleapis.com/' : No response received.
    

    也发生在 Chromium 版本 70.0.3538.67(开发人员构建)(64 位)(macOS、High Sierra)上。

    也许这个https://bugs.chromium.org/p/chromium/issues/detail?id=820945&can=2&start=0&num=100&q=geolocation&colspec=ID 是相关的。

    【讨论】:

      【解决方案3】:

      问题似乎解决了。我什么都没做。我认为这是一个公司代理问题。

      【讨论】:

        【解决方案4】:

        我工作场所的每个人目前在我们自己的代码和 Google Maps API 示例中都遇到了这个问题。

        Google 的网络位置提供商服务似乎周期性地不可用,导致所有无法通过其他方式(GPS 或蜂窝塔三角测量)确定位置的设备都会出现故障。

        老实说,这似乎是一个非常脆弱的实现 - 为什么没有 chrome 的后备网络位置提供程序?

        【讨论】:

          【解决方案5】:

          这也发生在我身上,花了 30 minz 试图找到解决方案,然后尝试重新启动

          【讨论】:

          • 一个类似的固定对我有用。我关闭了标签并重新打开它。尽管多个域不起作用(在不同的选项卡上)。这是 macOS Sierra 上的 Chrome 58
          • 是的,更新 Chrome 然后重启是唯一的方法。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-11-06
          • 1970-01-01
          • 2013-08-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-20
          相关资源
          最近更新 更多