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
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... :-)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With