navigator.geolocation无效 [英] navigator.geolocation not working
问题描述
我正在开发一个应用程序,需要我获取用户位置信息,并且我正在使用 navigator.geolocation
服务来处理相应的用户纬度和经度。下面是我必须检索其信息的代码。
I'm working on a application that requires I get the users location info and I'm using the navigator.geolocation
service to handle retriving the users latitude and longitude accordingly. Below is the code I have to retrieve their information.
let options = {maximumAge: 0, timeout: 5000, enableHighAccuracy: true};
navigator.geolocation.getCurrentPosition(function(position){
console.log(position);
console.log(navigator.geolocation);
}, function(error){console.log(error.message)});
console.log(navigator.geolocation);
但是,我在下面遇到此错误。
However, I keeping running into this error below.
Network location provider at 'https://www.googleapis.com/' : Returned error code 403.
我检查确认 navigator.geolocation $我的浏览器支持c $ c>服务(我正在使用Chrome),它甚至可以在控制台中记录该对象并证明它不是浏览器问题。 Google会强制某些计算机脱离其API存储库吗?我迷路了。
I checked to make sure the navigator.geolocation
service was supported by my browser (I'm using Chrome) and it is and even went to log the object in the console which works and proves its not a browser issue. Does Google force certain machines out of their API repository? I'm so lost.
推荐答案
快速检查控制台会发现此API仅适用于安全地址,因此禁止使用。
A quick check on console reveals that this API will work only on secure addresses, hence you're forbidden to use.
getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features for more details.
undefined
VM2552:4 Only secure origins are allowed (see: https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features)
这篇关于navigator.geolocation无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!