How to programmatically enable and disable GPS in Ionic Framework


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) {
                function(e) {
                    if (e){
                      alert("location on")
                    else {
                      alert("Location Not Turned ON");
                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;
  console.log("Successfully requested accuracy: "+success.message);

function onRequestFailure(error){
  $rootScope.isGpsEnabled = false;
  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?")){

you can call turnOnGps method from button.

plugin :

let me know is it working or not… :slight_smile:


@Sandy1 Thanks its working very fine :slight_smile:
Happy Coding :slight_smile:


:slight_smile: That’s great

I used same scenario in my app