在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 许可协议
我通过使用本机
LocationManager
的外部库找到了一个解决方案。它使用我想要的播放服务位置和发射位置事件。这里是图书馆; https://bitbucket.org/timhagn/react-native-google-locations#readme
并且在为android编译时,不要忘记包括
android/app/build.gradle
最后别忘了在 Android SDK Manager 中下载
Google Play Services
和Google Support Library
你可以找到你的播放服务版本;