Kwn*_*ios 0 javascript google-chrome geolocation
我正在尝试获取用户的地理位置,然后进行查询。在 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");
}
};
Run Code Online (Sandbox Code Playgroud)
我得到了 error 1
User denied the request for Geolocation.
Run Code Online (Sandbox Code Playgroud)
但我没有拒绝任何请求,实际上弹出窗口根本没有出现。
我已经转到 Chrome 设置 > 显示高级 > 隐私 > 内容设置 > 位置允许所有人。
重新启动chrome,什么也没发生。我确定我的代码是 100% 合法的,所以有人知道如何处理吗?谢谢!
好的,这很容易... Chrome 自 2016 年 4 月 20 日起禁用了不安全网站的 Geolocation API(没有 https)...链接在这里
https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only
所以别担心..
| 归档时间: |
|
| 查看次数: |
26977 次 |
| 最近记录: |