navigator.geolocation.getCurrentPosition回调不会在Firefox 10上工作 [英] navigator.geolocation.getCurrentPosition Callbacks wont work on Firefox 10

查看:182
本文介绍了navigator.geolocation.getCurrentPosition回调不会在Firefox 10上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在构建一个使用Geolocation API的应用程序。我无法得到一个非常简单的代码工作在Firefox 10.这是代码:
$ b $ pre $ window_onload = (){
如果(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
alert('works));
},function错误){
alert('Error occurred。Error code:'+ error.code);
});
} else {
alert('no geolocation support');
}
};所以,例如在chrome中,在运行完页面之后,我会被问到是否我想分享我的位置,然后点击是它会提醒我它的作品。现在在Firefox 10中,它会要求我分享我的位置,点击分享后它什么都不做......我一直在试图让回调运行任何类型的代码,但没有运气。这是一个Firefox的错误,或者我做错了什么?我有一个测试代码的例子: http://dev-hub.com/geolocation.html

编辑---
我的操作系统是windows 7 64bit

解决方案

好吧,我发现问题确实是Firefox,并且在所有平台上都无法可靠或平等地工作。查看 http://dev.w3.org/geo/api/spec-source .html 我发现以下选项可以添加:

  window.onload = function(){
(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
alert('works));
},function(error){
alert ('发生错误,错误代码:'+ error.code);
},{timeout:5000});
} else {
alert('no geolocation support');
}
};




$ b

正如你在这里看到的那样,超时时间是5000:这意味着如果由于某种原因浏览器需要超过5000ms(5秒),然后抛出一个超时错误(这是错误代码3)。所以,现在每当Firefox不工作,至少运行错误回调,我得到一个错误发生。错误代码:3的警报消息。显然,超时的默认值是无限的,所以它永远不会超时... Chrome是100%可靠的,但Firefox在我的机器上可靠性约为10%,这是非常令人失望的。在我的另一台运行Windows XP的电脑上,在同一个网络上,Firefox似乎是100%可靠的。


Ok so I am building an app that uses the Geolocation API. I cant seem to get a very simple piece of code to work on Firefox 10. Here is the code:

    window.onload = function() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function(position) {
                alert('it works');
            }, function(error) {
                alert('Error occurred. Error code: ' + error.code);         
            });
        }else{
            alert('no geolocation support');
        }
    };

So ,for example, in chrome, after running the page I will be asked if I want to share my location, and after clicking yes it will alert me with "it works". Now in Firefox 10 it will ask me to share my location and after clicking share it does nothing... I've been trying to get the callback to run any type of code but no luck. Is this a bug with Firefox or am I doing something wrong? I have an example of the code here for testing: http://dev-hub.com/geolocation.html.

Edit--- My OS is windows 7 64bit

解决方案

All right I found that the problem is indeed Firefox and that it does not work reliably or equally on all platforms. Looking at http://dev.w3.org/geo/api/spec-source.html I found the following option to add:

    window.onload = function() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function(position) {
                alert('it works');
            }, function(error) {
                alert('Error occurred. Error code: ' + error.code);         
            },{timeout:5000});
        }else{
            alert('no geolocation support');
        }
    };

As you can see here the timeout:5000 has been added which means that if for some reason the browser takes more then 5000ms (5 seconds) then throw a timeout error (that's error code 3). So now whenever Firefox is not working it at least runs the error callback and i get an alert message of "Error occurred. Error code: 3".

Apparently the default value of timeout is infinite so it never times out... Chrome is 100% reliable but Firefox is about 10% reliable on my machine which is very disappointing. On my other computer which is running windows XP and is on the same network, Firefox seems to be 100% reliable.

这篇关于navigator.geolocation.getCurrentPosition回调不会在Firefox 10上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆