【发布时间】:2014-02-09 16:26:19
【问题描述】:
我正在尝试使用 navigator.geolocation.getCurrentPosition() 函数进行地理定位,但我似乎无法让它在 Firefox 上运行。 更具体地说,我制作了一个非常简单的 HTML 文件:
<!DOCTYPE HTML>
<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="js/mapHandler.js"></script>
</head>
<body>
</body>
</html>
如您所见,它是 HTML 文件的最低限度。 javascript 只是执行以下操作:
function displayLocation (position)
{
alert("displayLocation");
}
function displayError(positionErr)
{
alert("error");
}
function initialize()
{
if (!(navigator.geolocation == 'undefined'))
{
navigator.geolocation.getCurrentPosition(displayLocation, displayError,{timeout:10000});
}
else
{
alert('Geolocation unsupported');
}
}
$(document).ready(function(){initialize() });
再一次,这是一个非常简单的例子,它只是询问位置并发出一些警报。 奇怪的是,当我启动脚本时,我似乎无法得到任何答案。 有谁知道为什么? 在此先感谢:)
【问题讨论】:
-
您使用的是哪个版本的 Firefox?
-
这个例子也适用于 FF。也许您没有启用位置共享。
-
在 2020 年仍然发生在我身上,使用 Firefox “开发者版” 76。真可惜。
标签: javascript jquery html