【发布时间】:2017-04-28 23:39:17
【问题描述】:
在 IOS 中查找 gps 坐标时没有问题。它工作正常。
在 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 }
);
}
欢迎任何类型的解决方案。
谢谢
【问题讨论】:
-
我读过这篇文章,对此没有有效的解决方案。也感谢您的关注
-
你有没有找到任何可行的解决方案。我面临同样的问题。我在任何地方都没有找到解决方案。
-
我解决了这个问题,这是我使用 promise 创建的组件:gist.github.com/a3diti/5466f7309752cbb2e63ecefff6365bb9 在 android 中我删除了 maximumAge,我将 enableHighAccuracy 保持为 true,并从 RN PermissionsAndroid 组件添加了权限检查。跨度>
标签: android react-native gps react-native-android