简体   繁体   English

要求用户在IONIC 3应用程序中激活地理定位

[英]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()" . 我正在使用Ionic 3本机Geolocation插件通过功能"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? 如何在应用程序开始时要求用户激活其android / ios地理位置?

I have the same problem, so I used a Toast as following: 我遇到了同样的问题,因此我按如下方式使用了Toast:

 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 我找到了一种更精确的方法: 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 使用2个离子本机插件:@ ionic-native / diagnostic @ ionic-native / location-accuracy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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