Issue
As title says, whether location is turned off or on success callback is always triggered. Anyone got any suggestions?
if (window.cordova) {
window.cordova.plugins.diagnostic.isLocationEnabled(locationEnabled,locationDisabled );
}
function locationEnabled() {.. }
function locationDisabled() {...}
I'm testing it on Samsung galaxy s5 with lolipop
Solution
The isLocationEnabled
does not work like you think.
The first function you pass as argument is the "success callback". It does not mean that location is enabled, it just means that the plugin has successfully retrieved the location status. A boolean is given as argument, and that is where you can know if location is enabled or not.
The second function you pass is the one that is called when the plugin can't fetch the location status.
So you need to make your code look like something like this:
function locationEnabled() {
// Blabla
}
function locationDisabled() {
// Blabla
}
if (window.cordova) {
window.cordova.plugins.diagnostic.isLocationEnabled(function (locationEnabled) {
if (locationEnabled) {
locationEnabled();
} else {
locationDisabled();
}
}, function (error) {
console.log("The following error occurred: " + error);
});
}
Check the plugin documentation for more details.
Answered By - Deurco
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.