小编İsm*_*ner的帖子

React Native Android位置请求超时

在IOS中,寻找gps coords时没有问题.它工作正常.

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

当我的应用程序无法找到我的位置时,我尝试通过谷歌地图应用程序,它就像魅力.

这是我的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 }
    );
}
Run Code Online (Sandbox Code Playgroud)

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

谢谢

gps android react-native react-native-android

19
推荐指数
6
解决办法
1万
查看次数

标签 统计

android ×1

gps ×1

react-native ×1

react-native-android ×1