How to programmatically enable and disable GPS in Ionic Framework
Hi @harry_monu
Check this conversation, this is very helpful for your requirement.
thanks for reply
if (window.cordova) {
cordova.plugins.diagnostic.isGpsLocationEnabled(
function(e) {
if (e){
alert("location on")
}
else {
alert("Location Not Turned ON");
cordova.plugins.diagnostic.switchToLocationSettings();
}
},
function(e) {
alert('Error ' + e);
}
);
}
i have this code for enable the location and its working very fine .but i wanted to enable my location via my mobile app
$rootScope.turnOnGps = function () {
if (ionic.Platform.isAndroid())
cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
};
function onRequestSuccess(success){
$rootScope.isGpsEnabled = true;
//getLocation();
console.log("Successfully requested accuracy: "+success.message);
}
function onRequestFailure(error){
$rootScope.isGpsEnabled = false;
$ionicLoading.hide();
console.error("Accuracy request failed: error code="+error.code+"; error message="+error.message);
if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){
cordova.plugins.diagnostic.switchToLocationSettings();
}
}
}
you can call turnOnGps method from button.
plugin : https://github.com/dpa99c/cordova-plugin-request-location-accuracy
let me know is it working or not…
2 Likes
@Sandy1 Thanks its working very fine
Happy Coding
1 Like
That’s great
I used same scenario in my app
1 Like
PLS ANSWER İMPORT cordova.plugins.diagnostic ionic 3
is this plugin work on ios?