ale*_*xsh 7 android geolocation react-native
如果最初关闭位置服务,则在打开时watchPosition不会调用该服务.作为一种解决方法,navigator.geolocation.getCurrentPosition如果发生错误,我将以递归方式调用.
watchPosition关闭位置服务时也不会调用.
在iOS上,一切都按预期工作.
任何建议将不胜感激
测试了Galaxy Note 5(Android 6.0.1)和不同的AVD仿真器,react-native v0.33
android.permission.ACCESS_FINE_LOCATION 包含在AndroidManifest.xml中
initialGeolocation(){
delete this.androidLocation;
navigator.geolocation.getCurrentPosition(
(position) => {
log('LOCATION getCurrentPosition success', position);
deviceActions.geolocation(position);
},
(error) => {
log('LOCATION getCurrentPosition error', error.message || error);
if (Platform.OS == 'android'){
this.androidLocation = setTimeout(this.initialGeolocation, 500);
}
},
{
enableHighAccuracy: (Platform.OS == 'android') ? false : true,
timeout: 10000,
maximumAge: 500
}
);
},
componentDidMount() {
this.initialGeolocation();
this.watchID = navigator.geolocation.watchPosition(
(position) => {
log('LOCATION watchPosition success', position);
deviceActions.geolocation(position);
},
(error) => {
log('LOCATION watchPosition error', error.message || error);
},
{
enableHighAccuracy: (Platform.OS == 'android') ? false : true,
distanceFilter: 10,
timeout: 10000,
maximumAge: 500
}
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
805 次 |
| 最近记录: |