1

I am trying to show toast message if GPS is enabled or if not show a GPS turn on request dialog and if accept then show the toast message in a ionic2 android app after view loaded. The problem is when I GPS not enabled app ask for turn it on by a dialog. But When I turn on GPS it doesn't show toast message "Loaded 2" but it shows "Loaded 2" in console log. How can I call this presentToastMsg function after request.

ionViewDidEnter() {
let options = {
  enableHighAccuracy: true,
  timeout: 1500
};

this.geolocation.getCurrentPosition(options).then((position) => {
  console.log('Loaded 1');
  this.presentToastMsg('Loaded 1');
}).catch(function (error) {
  cordova.plugins.locationAccuracy.canRequest(function (canRequest) {
    if (canRequest) {
      cordova.plugins.locationAccuracy.request(function (success) {
        console.log('Loaded 2');
        this.presentToastMsg('Loaded 2');
      }, function (error) {
        console.log(error);
        this.presentToastMsg(error);
      },
        cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
    }
  });
});
}

presentToastMsg(msg) {
let toast = this.toastCtrl.create({
  message: msg,
  duration: 3000,
  position: 'bottom',
  cssClass: "toast-info"
});

toast.present();
}
Matt
  • 1,893
  • 11
  • 33
  • 57
Randika
  • 683
  • 3
  • 11
  • 32

0 Answers0