3

GetCurrentLocation is working on Cordova/PhoneGap App even when the Location services are turned off in Android 4.4.2.

Cordova Version is 2.9

Device is Nexus4 V4.4.2

Code :

var onSuccess = function() {
    alert("success")
}
var onError = function() {
    alert("error")
}
var options = {
    maximumAge: 0,
    timeout: 60000,
    enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(onSuccess, onError, options);

Code is working fine in previous android versions. But in Android 4.4.2 it alerts success even if the location services are turned off.

Unable to find a solution, any help will be appreciated.

7
  • 1
    Please Update your Cordova Version
    – ChenSmile
    Apr 1, 2014 at 6:56
  • Hi Immi, Version 3.0 was a major update, will require much code changes and I dont have that much time Apr 1, 2014 at 7:44
  • Did you try to alert success coordinates? If they are undefined, simply check for it and treat it as error.
    – Regent
    Apr 1, 2014 at 7:51
  • @Regent they are not undefined Apr 1, 2014 at 9:22
  • Do they show correct values? If so, maybe you should restart phone after changing Location services' settings
    – Regent
    Apr 1, 2014 at 10:14

1 Answer 1

1

In Cordova V2.9 there was a bug related to current location mentioned here : GetCurrentLocation is working on Cordova/PhoneGap App even when the Location services are turned off in Android 4.4.2

As Cordova use the default browser's Geolocation implementation, it was a WebView bug mentioned here : https://issues.apache.org/jira/browse/CB-6548

As a workaround this plugin use Android API to check the status of the Location Services.

Plugin : https://github.com/mandeeppasbola/Cordova-Plugins/tree/master/Location%20Service%20Status

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.