简体   繁体   中英

Ask user to activate Geolocation in an IONIC 3 application

I'm using the Ionic 3 native Geolocation plugin to get the user position using the function "getCurrentPosition()" . But when the geolocation is not activated on my device I get the last saved position...

How can I ask users to activate their android/ios geolocation in the start of the app?

I have the same problem, so I used a Toast as following:

 import { ToastController } from 'ionic-angular'; ... constructor(private geolocation: Geolocation, private toastCtrl: ToastController) { ... let toast = this.toastCtrl.create({ message: 'Your device location is not available. Please turn on your GPS.', position: 'middle', showCloseButton: true, closeButtonText: 'OK' }); this.geolocation.getCurrentPosition().then((resp) => { //if location available - do whatever you need }).catch((error) => { toast.present(); console.log('Error getting location', error); }); } 

I found a more exact way : https://forum.ionicframework.com/t/how-to-check-if-geolocation-is-enable-or-not-with-native-gps/88762/4

using 2 ionic native plugins : @ionic-native/diagnostic @ionic-native/location-accuracy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM