首页 > 解决方案 > 使用 react-native-fused-location 什么都不返回

问题描述

我正在使用 react-native-android-location-enabler 来启用 gps,这样我们就可以获得用户位置 .. 这就是我所做的

RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({interval:10000,fastInterval: 5000}) .then(async (data) => { console.log(data); try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, { title: 'App needs to access your location', message: 'App needs access to your location ' + 'so we can let our app be even more awesome.' } ); if (granted == PermissionsAndroid.RESULTS.GRANTED) { FusedLocation.setLocationPriority(FusedLocation.Constants.HIGH_ACCURACY); const location = await FusedLocation.getFusedLocation(); console.log(location); } else { console.log('Not granted'); } } catch (err) { console.log('err',err); } }).catch(err => { console.log(err); });

如果 gps 在此代码之前关闭,它将要求将其打开,则 fusedLocation 根本不返回任何内容(甚至没有错误)...如果先前打开了 gps,则 fusedLocation 工作正常。

"react-native": "0.54.2",
"react-native-android-location-enabler": "^1.0.5",
"react-native-fused-location": "^0.2.1",
"react-native-maps": "https://github.com/react-community/react-native-maps.git"

标签: react-native-android

解决方案


推荐阅读