navigator.geolocation.getCurrentPosition总是得到一个错误code 3:超时过期 [英] navigator.geolocation.getCurrentPosition always get a error code 3: timeout expired

查看:4563
本文介绍了navigator.geolocation.getCurrentPosition总是得到一个错误code 3:超时过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的科尔多瓦-2.0.0和Android模拟器谷歌API level16。

I am using cordova-2.0.0 and android emulator google api level16.

每当我跑 navigator.geolocation.getCurrentPosition 我总是误差3 。 我的code简单是因为:

Whenever I run navigator.geolocation.getCurrentPosition I always get error3. my code brief is as:

     // Wait for Cordova to load
            document.addEventListener("deviceready", onDeviceReady, false);

            // Cordova is ready
            function onDeviceReady() {
                console.log("Entering index.html.onDeviceReady");
                var networkState = navigator.network.connection.type;
                getPosition(networkState);
}

function getPosition(networkState) {
    console.log("Entering getPosition function");
    console.log("networkState is: " + networkState);
    if (networkState !== null) {
        navigator.geolocation.getCurrentPosition(onSuccess, onError, {
            maximumAge : Infinity,
            timeout : 5000,
            enableHighAccuracy : true
        });
    } else {
        alert('Please check your network connection and try again.');
    }
    console.log("Leaving getPosition function");
}

// function for lat & lng
function onSuccess(position) {
    console.log("Entering onSuccess(position) function");
    console.log("Latitude is: " + position.coords.latitude);
    console.log("longitude is: " + position.coords.longitude);
    lat = position.coords.latitude;
    lng = position.coords.longitude;
    console.log("Leaving onSuccess(position) function");
}

// function for lat & lng
function onError(error) {
    console.log("Entering onError(error) function");
    alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
    console.log("Leaving onError(error) function");
}

如果任何人有想法,为什么误差3 上升,请给点建议。非常感谢

If anyone have idea why error3 is raised, please give suggestions. Thanks a lot

推荐答案

我没设置

enableHighAccuracy: false

太多,但害怕错误code 3不停地弹出了... 无论

too, but dreading "error code 3" kept popping out... Neither

browser / settings / privacy and security / position / delete position access data

确实帮助... 只有功率循环(但我想浏览器杀会做同样的)安卓(4.1.2)没有强制浏览器重复问题份额第一的位置?给用户,抛出错误code 3出了门......

did help... Only power cycling (but I suppose a browser kill would do the same) Android (4.1.2) did force the browser to repeat the question "Share position?" to the user, throw error code 3 out of the door...

我想在某些情况下(即我不能重复,不好意思)浏览器存储为该网站一个无效的位置 - 或 - 记得共享拒绝该网站...

I suppose in some situation (that I can't repeat, sorry) the browser stores an invalid position for that site - or - remembers a sharing denial for that site...

对不起,我迟到应答(也许在一个不完整的方式)......如果有人有更有力的证据,请分享...: - )

Sorry for late answering (and perhaps in an incomplete way)... If somebody has better evidence please share it... :-)

这篇关于navigator.geolocation.getCurrentPosition总是得到一个错误code 3:超时过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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