Reputation: 8877
I have developed an app which is now live on Google Play store. The app uses the getCurrentPosition
method to get the current location of a user.
I have tested on a few devices, and the code works perfectly. Those devices being the Nexus 4, Nexus 5, Samsung Galaxy S3 and S4. Perfect.
I have now found issues with the app on Android devices lower than 4.1 (namely 4.0.4, which seems the most used version other than those mentioned).
The app constantly returns a timeout error. I know location services are switched on on the device.
I have amended the options for getCurrentPosition
and included a maximumAge
, timeout
and enableHighAccuracy
. I have tried all sorts of options; from reasonable timeouts/ages, low timeouts/ages to high timeouts/ages. I have tried turning enableHighAccuracy
on (true
) and off (false
) in all permutations. The timeout is being taken into account (eg. the error callback isn't being hit until timeout is reached).
There are a few similar threads on StackOverflow, but none match my problem. I have tried turning the device off, deleting and re-adding the app, and recompiled it several times. Same issue.
The device being tested is a HTC Sensation, but I have also tried on a HTC Wildfire, and there are similar bug reports coming from users out in the wild - all the same.
Below is sample code, but like I say, I've tried all sorts of options (higher age than timeout, higher timeout than age, high accuracy on and off in both cases, etc).
if (navigator.geolocation) navigator.geolocation.getCurrentPosition(function(pos) {
console.log('Working...');
}, function(error, msg) {
console.log(error.code + ' - '+ error.message);
},
{ maximumAge: 90000, timeout: 9000, enableHighAccuracy: false });
LogCat spits out: 3 - Position retrieval timed out. at file:///[...]
Update: Changing to watchPosition
has no effect, the device will not find the location still.
Upvotes: 4
Views: 1305
Reputation: 410
For me, the geolocation plugin had not successfully installed for some reason. Run cordova plugins list
to make sure that cordova-plugin-geolocation is there. If not, run cordova plugins add cordova-plugin-geolocation
. Sometimes removing and re-adding a plugin or entire platform will fix errors as well.
Upvotes: 0
Reputation: 8877
This was a problem with the device rather than a problem with Android (possibly) or Phonegap (certainly). Location based services were not working on the default Android Browser, or anything that uses the native browser (Maps app DOES work).
I fixed this on the device by turning off location services, rebooting the device and restarting all location services, forcing re-acceptance of terms/certificates/etc. Location services then sprung into life, browser found where I was and the app worked as it should.
Found a few people complaining of this online, and I've experienced it on more than one device running the same Android version.
Upvotes: 1