am having task to find the geo location for get the current position.the problem am facing is when i run the app first time it shows the answer,if i run the app as repeatedly means it shows error:
code: 2
message: The operation couldn’t be completed. (kCLErrorDomain error 0.)
the code is given below:
document.addEventListener("deviceready", onDeviceReady, false);
var watchID = null;
// PhoneGap is ready
//
function onDeviceReady() {
// Update every 3 seconds
var options = { frequency: 3000 };
watchID = navigator.geolocation.getPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
//
function onSuccess(position) {
alert(position);
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'<hr />' + element.innerHTML;
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
console.log('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
i run the app only in simulator.i don't know whats going wrong?