Hi guys
I’ve been using Ionic for a while and know my ways around it but I recently bumped into an issue which I cannot solve.
All I am trying to do is get the user’s location when the app loads. For this I am using a controller that on the deviceready event listener will use NgCordova’s geolocation to get the users location.
My code works perfectly most of the time. The only times it WONT WORK is when a user launch’s the app and gets the “My App would like to use your location prompt” AND waits for 30 seconds (the timeout time). If a user waits for 30 seconds before allowing the app to use the location the location code will timeout. This is the error I get (this is all done on iOs):
Error
PositionError {
message: “Timeout expired”,
code: 3,
PERMISSION_DENIED: 1,
POSITION_UNAVAILABLE: 2,
TIMEOUT: 3
}
My Code
.controller('NearbyCtrl', function($cordovaGeolocation) {
document.addEventListener("deviceready", function(){
var posOptions = {timeout: 30000, enableHighAccuracy: false};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
alert(lat + ", " + long);
}, function(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
});
}, false);
});
I have tried also use enableHighAccuracy: true but get the same results.
Any ideas would be appreciated! Thanks