Jeremy Belolo
Jeremy Belolo

Reputation: 4539

Cordova / Phonegap geolocation from GPS, Network and Wifi

So I started this app using Cordova and integrated Google Maps with API V3. When using geolocation like so :

navigator.geolocation.watchPosition(onSuccessLoc, onErrorLoc, { maximumAge: 3000, enableHighAccuracy: true });

I get the position with the help of the GPS. Therefore I need to be outside. If I stay inside it won't lock, I could wait forever. But when removing options and calling simply like this : navigator.geolocation.watchPosition(onSuccessLoc, onErrorLoc);

Then it locates me with the help of wifi and network, but no GPS.

I would like to get both, just like native apps do !

Thanks ahead for any help !

Upvotes: 1

Views: 3278

Answers (2)

Jeremy Belolo
Jeremy Belolo

Reputation: 4539

So upgrading to Cordova 3.4.0 seems to have fixed the issue ! Try this if you run into the same problem.

Upvotes: 0

Dawson Loudon
Dawson Loudon

Reputation: 6029

What if you created a fallback method so if the highAccuracy check doesn't take it calls the wifi/network method. Something like this:

navigator.geolocation.watchPosition(onSuccessLoc, onErrorLoc, { maximumAge: 3000, enableHighAccuracy: true });

function onErrorLoc() {
     navigator.geolocation.getCurrentPosition(onSuccessLoc, onErrorFinal);
}

This would allow for the watching method to continue to run, but if no location is found using that method it would call a one time position check using the looser location method.

Upvotes: 1

Related Questions