我正在尝试获取用户的地理位置,然后进行查询。
在 Mozilla Firefox 中它在 Safari 中也可以正常工作......但在 Chrome 中它根本不起作用。
window.onload = function(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var latitude = position.coords.latitude,
longitude = position.coords.longitude;
console.log(latitude + " " + longitude);
},handleError);
function handleError(error){
//Handle Errors
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.");
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
console.log("An unknown error occurred.");
break;
}
}
}else{
// container.innerHTML = "Geolocation is not Supported for this browser/OS.";
alert("Geolocation is not Supported for this browser/OS");
}
};
我得到了error 1
User denied the request for Geolocation.
但我没有拒绝任何请求,实际上弹出窗口根本没有出现。
我已经转到Chrome设置>显示高级>隐私>内容设置>位置允许所有人。
重新启动chrome,什么也没发生。我确信我的代码 100% 合法,所以有人知道如何处理它吗?
谢谢!
好吧,这很简单...Chrome 自 2016 年 4 月 20 日起已禁用不安全网站的地理定位 API(没有 https)...链接在这里
https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only
所以不用担心..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)