How to check\moniter gps is turned on or off in ionic

I am working on app where gps is important key factor…

but I m not able to check gps is turned ON or OFF when app start as well as while app is running…??

Can anybody help me on this this…Please :slight_smile:

I found some import Diagnostic…

but not able to code it however it is opening gps settings in mobile but how to use to detect whether GPS is turn ON or OFF… ???

Diagnostic.registerLocationStateChangeHandler((state)=>{
});

you can try this

Hi there, Please use this code
if (this.platform.is(‘android’)) {
let successCallback = (isAvailable) => { console.log('Is available? ’ + isAvailable); };
let errorCallback = (e) => console.error(e);

  this.diagnostic.isLocationAvailable().then(successCallback).catch(errorCallback);

  this.diagnostic.isGpsLocationAvailable().then(successCallback, errorCallback);


  this.diagnostic.getLocationMode()
    .then((state) => {
      if (state == this.diagnostic.locationMode.LOCATION_OFF) {
        let confirm = this.alertCtrl.create({
          title: '<b>Location</b>',
          message: 'Location information is unavaliable on this device. Go to Settings to enable Location for Untapped.',
          buttons: [

            {
              text: 'GO TO SETTINGS',
              handler: () => {
                this.diagnostic.switchToLocationSettings();

              }
            }
          ]
        });
        confirm.present();
      } else {


        this.FinalSave();
      }
    }).catch(e => console.error(e));
}

why you use getLocationMode() because isGpsLocationAvailable() is also doing same thing? we can put below code in isGpsLocationAvailable() right? Then what is main purpose to use both of this.

1 Like

it not working if user is jump to locationSetting button click mobile back button how to manage