getCurrentPosition()在Firefox中不起作用 [英] getCurrentPosition() not working in firefox
问题描述
我试图用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 / javascriptsrc =http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js>< / script>
< script type =text / javascriptsrc =js / mapHandler.js>< / script>
< / head>
< body>
< / body>
< / html>
正如您所看到的,它是HTML文件的最低限度。
JavaScript仅执行以下操作:
函数displayLocation(position)
{
alert ( displayLocation);
}
函数displayError(positionErr)
{
alert(error);
}
函数initialize()
{
if(!(navigator.geolocation =='undefined'))
{
navigator.geolocation.getCurrentPosition (displayLocation,displayError,{timeout:10000});
}
else
{
alert('Geolocation unsupported');
$(document).ready(function(){initialize()});
再一次,这是一个非常简单的例子,只是询问这个位置,并提出了一些警告。
奇怪的是,当我启动脚本时,我似乎无法得到任何答案。
有人知道为什么吗?
在此先感谢:)
实际上,我在Chrome 32(它工作正常)和Firefox 26没有运气)。
我尝试在Firefox上启用地理位置,但仍然无法正常工作。
我浏览过情侣网站上的谷歌,最后我明白的是Firefox 26& 27在检测地理位置时存在一个错误。
为了测试功能,您可以运行这个 LIVE DEMO 这是一个普通的javascript。
初始化();
function displayLocation(position){
var cords = position.coords;
alert(displayLocation,lat ='+ cords.latitude +'; long ='+ cords.longitude +');
function displayError(positionErr){
alert(error);
函数initialize(){
if(!(navigator.geolocation =='undefined')){
navigator.geolocation.getCurrentPosition(displayLocation,displayError ,{
timeout:10000
});
} else {
alert('Geolocation unsupported');
}
}
I'm trying to geolocate with the navigator.geolocation.getCurrentPosition() function, but I can't seem to get it working on firefox. More specifically, I made a very simple HTML file:
<!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>
As you can see, it's the bare minimum of an HTML file. The javascript just does the following:
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() });
Once again, it's a very very simple example which just asks for the position and makes a couple of alert. The strange thing is that when I launch the script I can't seem to get any answer. Does anyone know why? Thanks in advance :)
Actually I tested it on Chrome 32(It worked fine) and Firefox 26 (No luck).
I tried enabling geolocation on Firefox but still doesn't work.
I have browsed couple sites on the google and finally What I understood is Firefox 26 & 27 has a bug in detecting the geolocation.
For testing the functionality, you can run this LIVE DEMO which is a plain javascript.
initialize();
function displayLocation(position) {
var cords = position.coords;
alert("displayLocation, lat='"+cords.latitude+"'; long='"+cords.longitude+"'");
}
function displayError(positionErr) {
alert("error");
}
function initialize() {
if (!(navigator.geolocation == 'undefined')) {
navigator.geolocation.getCurrentPosition(displayLocation, displayError, {
timeout: 10000
});
} else {
alert('Geolocation unsupported');
}
}
这篇关于getCurrentPosition()在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!