首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >navigator.geolocation.getCurrentPosition总是得到一个错误代码3:超时过期

navigator.geolocation.getCurrentPosition总是得到一个错误代码3:超时过期
EN

Stack Overflow用户
提问于 2012-10-01 20:19:15
回答 2查看 14.8K关注 0票数 13

我正在使用cordova-2.0.0和安卓模拟器google level16。

每当我运行navigator.geolocation.getCurrentPosition时,我总是得到error3。我的代码简介如下:

代码语言:javascript
复制
     // 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");
}

如果有人知道为什么error3 会被提出来,请给出建议。非常感谢

EN

回答 2

Stack Overflow用户

发布于 2013-04-23 14:31:13

我确实

代码语言:javascript
复制
enableHighAccuracy: false

也是,但是害怕“错误代码3”不断冒出来.都不是

代码语言:javascript
复制
browser / settings / privacy and security / position / delete position access data

确实有帮助..。只有电力循环(但我想浏览器杀死也会做同样的) Android (4.1.2)迫使浏览器重复“共享位置”这个问题?向用户抛出错误代码3.

我想在某些情况下(我不能重复,对不起),浏览器为该站点存储一个无效的位置-或者-记住该站点的共享拒绝.

抱歉没有及时回答(也许是不完整的).如果有人有更好的证据请分享..。:-)

票数 5
EN

Stack Overflow用户

发布于 2012-10-28 04:23:46

这使我困惑了很长一段时间。基本上,我能让它返回数据的唯一方法就是通过特定的传递

代码语言:javascript
复制
enableHighAccuracy: false

如果我启用它,它总是超时的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12680444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档