【问题标题】:HTML5 Geolocation not working even after all options are set [duplicate]即使设置了所有选项,HTML5 地理位置也无法正常工作[重复]
【发布时间】:2013-09-13 06:01:40
【问题描述】:
var x=document.getElementById("demo");
function getLocation()
{
  if (navigator.geolocation)
    navigator.geolocation.getCurrentPosition(showPosition,showError);
  else
    x.innerHTML="Geolocation is not supported by this browser.";    
}

function showPosition(position)
{
  x.innerHTML="Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude;    
}

function showError(error)
{
  switch(error.code) 
  {
    case error.PERMISSION_DENIED:
      alert("User denied the request for Geolocation.");
      break;
    case error.POSITION_UNAVAILABLE:
      alert("Location information is unavailable.");
      break;
    case error.TIMEOUT:
      alert("The request to get user location timed out.");
      break;
    case error.UNKNOWN_ERROR:
      alert("An unknown error occurred.");
      break;
  }
}

我已经激活了谷歌地图地理定位服务,并在浏览器中勾选了“允许站点访问物理位置​​”选项。但仍然会抛出“PERMISSION_DENIED”错误代码。

【问题讨论】:

标签: javascript html google-chrome


【解决方案1】:

在 http 服务器的帮助下可以正常工作。在 Chrome 中使用来自“file:/// URI”的地理位置存在一些安全限制问题。 Chrome 也无法通过 'file:///' uri 读取像 XML 这样的外部文件。

【讨论】:

    猜你喜欢
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2011-04-27
    • 2015-05-13
    • 1970-01-01
    • 2017-12-11
    相关资源
    最近更新 更多