React Native Android 位置请求超时

新手上路,请多包涵

在IOS中寻找gps坐标时没有问题。它工作正常。

在 Android 方面,它不像 IOS 那样稳定。这个问题在真实设备和模拟器中都有。有时它可以找到位置,但有时不能。找了 3 天,但没有找到解决方案。

当我的应用程序找不到我的位置时,我尝试通过 Google 地图应用程序,它就像魅力一样。

这是我的IOS和Android代码;

 getCurrentPosition() {
    navigator.geolocation.getCurrentPosition(
        (position) => {
            this.setState({ initialPosition: position });
            alert(JSON.stringify(position))
            var coords = new Coords();
            coords.Latitude = position.coords.latitude;
            coords.Longitude = position.coords.longitude;
            this.getPharmaciesByCoordinates(coords);
        },
        (error) => alert(error.message),
        { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
    );
    this.watchID = navigator.geolocation.watchPosition((position) => {
        this.setState({ initialPosition: position });
    },
        (error) => alert(error.message),
        { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
    );
}

欢迎任何类型的解决方案。

谢谢

原文由 İsmail Şener 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 600
2 个回答

我通过使用本机 LocationManager 的外部库找到了一个解决方案。它使用我想要的播放服务位置和发射位置事件。

这里是图书馆; https://bitbucket.org/timhagn/react-native-google-locations#readme

并且在为android编译时,不要忘记包括 android/app/build.gradle

 dependencies {
    ...
    compile "com.google.android.gms:play-services:10.0.1" -> which version that you have write down here.
    ...
}

最后别忘了在 Android SDK Manager 中下载 Google Play ServicesGoogle Support Library 你可以找到你的播放服务版本;

 <android-sdk-location>/<sdk-version>/extras/google/m2repository/com/google/android/gms/play-services

原文由 İsmail Şener 发布,翻译遵循 CC BY-SA 3.0 许可协议

我在 Android 上删除了 maximumAge: 3600000 并且它可以正常工作

原文由 Thai Ha 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏