How to check gps is enable or not?

#1

hi everyone,
i want to check gps is enable or not, if gps is disable will appear popup notification to enable that like in the native apps.

Can someone give me a few example on how to get this working?

How to programmatically enable and disable GPS in Ionic Framework
#2

Check Cordova Geo location plugin

#3

but how to open android location settings ? i don’t found it

#4

here you go http://stackoverflow.com/questions/13006454/use-phonegap-to-check-if-gps-is-enabled

#5

thanks TheJetlag… i’ll try

#6

I have found one android based plugin for this… hope this helps you

#7
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);
                }
            );
        }
#8

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));
}
1 Like
#9

how to check ios platform