【发布时间】:2016-09-13 09:04:12
【问题描述】:
我正在尝试获取用户的地理位置,然后进行查询。 在 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% 合法的,所以有人知道如何处理它吗? 谢谢!
【问题讨论】:
标签: javascript google-chrome geolocation