Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigator.geolocation.getCurrentPosition always get a error code 3: timeout expired

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

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");
}

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

like image 248
user1712576 Avatar asked Oct 01 '12 20:10

user1712576


2 Answers

I did set

enableHighAccuracy: false

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

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

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... :-)

like image 56
MarcoS Avatar answered Nov 16 '22 03:11

MarcoS


This stumped me for quite a while. Basically the only way I can get it to return data is by specifically passing

enableHighAccuracy: false

It always times out if I enable it.

like image 34
Aaron C. de Bruyn Avatar answered Nov 16 '22 04:11

Aaron C. de Bruyn