我正在使用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,则fusionLocation可以正常工作好的。
"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"