【问题标题】:Google chrome geolocation not working [duplicate]谷歌浏览器地理定位不起作用[重复]
【发布时间】:2015-11-26 15:09:45
【问题描述】:

我正在开发跨平台应用程序。 navigator.geolocation 工作正常,但从过去 2 天开始,它只是在 Google chrome 中出现问题。 该 api 是否已弃用或此 api 的其他问题?我在许多不同的浏览器和网络上测试了以下代码,但仍然是同样的问题。

var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};

function success(pos) {
  var crd = pos.coords;

  console.log('Your current position is:');
  console.log('Latitude : ' + crd.latitude);
  console.log('Longitude: ' + crd.longitude);
  console.log('More or less ' + crd.accuracy + ' meters.');
};

function error(err) {
  console.warn('ERROR(' + err.code + '): ' + err.message);
};

navigator.geolocation.getCurrentPosition(success, error, options);

ERROR(2): 'https://www.googleapis.com/' 处的网络位置提供程序:返回错误代码 403。

【问题讨论】:

  • googleapis.com 不存在。 ajax.googleapis.com 确实如此。你在尝试to use one of these libraries吗?
  • 你也得到...getCurrentPosition() and watchPosition() are deprecated on insecure origins, and support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
  • 我遇到了同样的问题。 OS X 上的 Chrome 44 最新版本。我在外部站点上收到了不安全的弃用警告,但在本地运行时没有这样的警告(通过 file:// 协议或 localhost)。同样的 403 错误,同样的消息。
  • 不,它只是给了我一个错误:ERROR(2): Network location provider at 'googleapis.com' : Returned error code 403.
  • 是的,我认为这可能是问题所在。 2 个月前 chrome 43 还更改了一些 api,导致 sencha touch 滚动出现问题。

标签: javascript google-chrome geolocation w3c-geolocation


【解决方案1】:

最新的 chrome 已在非安全来源上弃用此 API:

https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

是时候让https://localhost 启动并运行了;)

对于未来的查询... https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only?hl=en

【讨论】:

  • 我不这么认为,这对我来说在定义为安全域的本地主机上也失败了。
【解决方案2】:

现在似乎已修复。由于谷歌所做的服务器端更改,一定是一个问题。当我调试时,我发现了一个速率限制问题,即使我在https://www.google.com 的控制台中运行 getCurrentPosition() 调用也是如此。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-28
    • 2016-09-21
    • 1970-01-01
    • 2013-09-28
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多