2016-05-17 48 views
-1

我正在尝试将用户的地理位置,然后做一个查询。 在Mozilla Firefox中,它在Safari中也能正常工作......但在Chrome中它根本不起作用。Javascript地理位置不能在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%合法的,所以有人知道如何处理它? 谢谢!

回答

2

最简单的方法是点击地址栏左侧的区域并在那里更改位置设置。它允许在网上,而不是设置甚至file:///位置选项和所有其他类型的

enter image description here

相关问题