I tried and struggled for several days to get the Cordova V3.4, GPS Plugin to work properly. I see on the internet and also here for a lot of solution and suggestion, but non of them solved this issue.
The issue is occur only on Phone Gap Apps[with APK Deploy on Device or in Simulator] (In browser the GPS work fine).
Testing Details:
- Phone: Nexus 5 And Samsung Galaxi 2.
- Simulator: Android Regular Simulator And GenyMotion Simulator.
Cordova Installation: By CLI
- I added geolocation plugin by CLI
I added Permission to AndroiedManifest:
uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" uses-permission android:name="android.permission.INTERNET" uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
- in config.xml: plugin name="Geolocation" value="org.apache.cordova.GeoBroker"
ISSUE:
After Clean Reboot:(Without GPS)
- I enter my app and I an get error with error code - As expected :)
- I Enable the GPS, re Enter my App, and see the location of my place - As Expected
- I Disable the GPS, re Enter my App, and see other location of my place - As Expected
- GPS Disable, re enter to my App, and see the SAME POINT AS BEFORE(I dont know how but it cache it - I disable the maximumAge option by put it with value 0)
- GPS Disable, Wireless Disable, 3G Network Disable, I run my App and I get the latest location Same As Point 4. And Now the same issue happens forever and i will get the same position till i will turn on my GPS OR I will reboot my device.
P.S: BTW I tried also to work just with HTML5 Geo Location and I get the SAME ISSUE.
My code: (I tried several times but this is the latest that I've tried to use. I try two call to getCurrentPosition because I read that sometimes one call is Not enough :():
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
var str = 'Your current position is:'+'Latitude : ' + crd.latitude+'Longitude: ' + crd.longitude+'More or less ' + crd.accuracy + ' meters.' + ' TimeStap : ' + crd.ti;
alert(str);
}
function error1(err) {
alert('error 1');
alert('ERROR(' + err.code + '): ' + err.message);
var options = {
enableHighAccuracy: false,
timeout: 5000,
maximumAge: 0
};
navigator.geolocation.getCurrentPosition(success, error2, options);
}
function error2(err){
alert('error 2');
alert('ERROR(' + err.code + '): ' + err.message);
}
navigator.geolocation.getCurrentPosition(success, error1, options);
},