React Native Android位置请求超时 [英] React Native Android location request timed out
问题描述
在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}
);
}
欢迎任何形式的解决方案。
谢谢
本地 LocationManager
。它使用播放服务的位置和发射位置事件,因为我想。
这是图书馆;
https://bitbucket.org/timhagn/react-native- google-locations#readme
当为android编译时,不要忘记包含 android / app / build.gradle
依赖关系{
...
compilecom.google.android .gms:play-services:10.0.1 - >你在这里写下了哪个版本。
...
}
最后不要忘记下载 Google Play服务
和 Google支持库
位于 Android SDK Manager 中,您可以找到您的Play服务版本到;
< android-sdk-location> /< sdk-version> / extras / google / m2repository / com / google / android / gms / play-services
In IOS there isn't a problem while looking for gps coords. It works fine.
On Android side its not stable as IOS. This problem both in real device and emulator. Sometimes it can find location, but sometimes not. Looking for 3days but there wasn't find a solution.
When my app cannot find my location, I tried via Google Maps app, it works like charm.
Here is my code for both IOS and 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 }
);
}
Any kind of solution is welcome.
Thanks
I found a solution via external lib that uses native LocationManager
. It uses play services location and emitting location event as I want.
Here is the library; https://bitbucket.org/timhagn/react-native-google-locations#readme
And when compiling for android, don't forget to include android/app/build.gradle
dependencies {
...
compile "com.google.android.gms:play-services:10.0.1" -> which version that you have write down here.
...
}
And finally don't forget to download Google Play Services
and Google Support Library
in Android SDK Manager you can find your play services versions into;
<android-sdk-location>/<sdk-version>/extras/google/m2repository/com/google/android/gms/play-services
这篇关于React Native Android位置请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!