【发布时间】:2018-12-09 16:56:37
【问题描述】:
我正在使用 Ionic/Angular/Firebase 构建一个应用程序。
该应用程序需要用户的地理位置。我正在使用 Ionic native 的地理位置插件,但在 Android 速度方面遇到了一些问题。
在 PC 上,获取电流的时间不到 500 毫秒 地理位置。
在 iOS 上大约需要 1 秒。
在 Android 上需要 6 多秒,有时甚至完全失败。
这是 Ionic Native 的问题吗?有专门的安卓插件吗?
这是我的代码:
this.geolocation.getCurrentPosition({enableHighAccuracy: false, timeout: 3000, maximumAge: 100000}).then((resp) => {
this.userLocation.lat = resp.coords.latitude;
this.userLocation.lng = resp.coords.longitude;
this.getLocation();
}).catch((error) => {
this.geolocation.getCurrentPosition({enableHighAccuracy: true, timeout: 3000, maximumAge: 100000}).then((resp) => {
this.userLocation.lat = resp.coords.latitude;
this.userLocation.lng = resp.coords.longitude;
this.getLocation();
}).catch((error) => {
this.userLocation.lat = this.userData.location.lat || 0;
this.userLocation.lng = this.userData.location.lng || 0;
//if fails, get users last known location.
this.getLocation();
console.log('Error getting location', error);
});
console.log('Error getting location', error);
});
我无法想象这段代码是错误的。正如我所说,它在 PC 和 iOS 上运行得非常好。如果用户使用的是 android,我应该做些什么吗?我可以使用其他插件吗?任何帮助都会很棒!
【问题讨论】:
-
哪个android版本失败了?
-
@SurajRao 我正在使用默认 android 操作系统的三星 s8 上进行测试。
-
您是要获取坐标还是地址?
-
@MayankRaj 只是坐标
-
我们在最近的编程冒险中发现了一个非代码原因。一位用户经常摔倒她的手机,导致她的 SD 卡连接不良。因此,定位服务会静默失败或耗时过长。
标签: javascript cordova ionic-framework ionic2 cordova-plugins