javascript 谷歌浏览器地理定位不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32330623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 15:07:05  来源:igfitidea点击:

Google chrome geolocation not working

javascriptgoogle-chromegeolocationw3c-geolocation

提问by Bilal Akmal

I'm working on cross platform application. navigator.geolocation was working fine, but since last 2 days it just giving problem in Google chrome. Is the api deprecated or some other issue for this api? I tested following code on many different browsers and network but still the same issue.

我正在研究跨平台应用程序。navigator.geolocation 工作正常,但自过去 2 天以来,它只是在谷歌浏览器中出现问题。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): Network location provider at 'https://www.googleapis.com/' : Returned error code 403.

错误(2):“ https://www.googleapis.com/”上的网络位置提供者:返回错误代码 403。

回答by Chip Kellam

This appears to be fixed now. Must have been an issue due to a server-side change google made. When I was debugging I was seeing a rate limit issue, even when I ran the getCurrentPosition() call in console on https://www.google.com.

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