似乎在MacOs、Linux Mint和Windows上的新chrome版本地理位置不工作!它返回错误:错误(2):位于"https://www.googleapis.com/"的网络位置提供程序:返回错误代码403。
有人有同样的问题吗?
一定是Chrome最新版本的错误,也发生在谷歌地图API的页面:https://developers.google.com/maps/documentation/javascript/examples/map-geolocation
希望能尽快修好。
编辑:现在试一下,它的工作:)
显然这个API已经被禁止从不安全的位置访问,见这里
我在这里提交了一个bug ticket: https://productforums.google.com/forum/?utm_medium=email&utm_source=footer#!味精/铬/q7B6gjCr1ps/Y9DEXPZ -_HYJ
请随意在那里评论,星号等
后续查询:
https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only?hl=en从Chrome 50开始,Chrome不再支持使用HTML5地理定位API从非安全连接传递的页面获取用户的位置。这意味着进行Geolocation API调用的页面必须从安全上下文(如HTTPS)提供服务。
这将破坏你的网页应用在chrome上,如果你不使用HTTPS。
我没有得到任何解决方案的" Returned error code 403
",但我发现一个解决方案,以获得当前位置,如果谷歌api失败
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
current_location_lat = position.coords.latitude;
current_location_lon = position.coords.longitude;
}, function (error) {
//if error occurred by google api
$.getJSON("http://ipinfo.io", function (ipinfo) {
var latLong = ipinfo.loc.split(",");
current_location_lat = latLong[0];
current_location_lon = latLong[1];
});
});
} else {
// Browser doesn't support Geolocation
alert("Error: Your browser doesn't support geolocation");
}