首页 > 解决方案 > ionic 3 地理位置无法在真实设备上运行

问题描述

离子的地理位置代码:

this.geolocation.getCurrentPosition().then( pos =>{

      this.lat = pos.coords.latitude;     
      this.long = pos.coords.longitude;
}).catch(err => this.presentToast(err));

标签: ionic3

解决方案


1)我们必须安装插件的兼容版本,在我的情况下 "@ionic-native/geolocation": "^4.4.2"

2)我们必须把它放在packaje.json依赖中,只需将此版本复制到 packaje 在我的情况下它是 4.4.2

3)我们必须像这样重新安装后运行这个cmd来取下node_modules rm -rf node_modules/

4)在安装之前必须清理缓存之后 npm cache clean --force

5) 现在通过运行这个 cmd 命令重新安装 node_module npm install

6)在我使用visual studio IDE的情况下,我的存储有问题,我用一个小技巧解决了,但我不知道为什么,只需取下存储ctrl + x并重新放回去ctrl + v。并准备使用我的应用程序。

在您的手机中还有一件事,您必须授予 gps 权限才能使用它。

希望这对你有帮助


推荐阅读