react-native-android - 使用 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"
解决方案
推荐阅读
- javascript - 我正在尝试使用 vanilla JS 突出显示单击的锚点并删除先前突出显示的锚点
- php - 禁用特定“品牌”自定义字段值的 WooCommerce 添加到购物车按钮
- c# - 如何将 X-Frame-Options 从 DENY 更改为 SAMEORIGIN
- javascript - 使用 Discord.js/opus 将 Wav 转换为 Opus 会静默失败
- matplotlib - tkinter画布问题中的matplotlib绘图工具栏几何管理器
- neural-network - 如何在 FastAi 中查看神经网络模型内部架构(嵌入模块列表)和(层)细节?
- docker - 从主机 SSH 到 docker 容器
- c# - Blazor WASM 与数据表的集成(使用 ajax)
- flutter - Flutter 堆栈布局容器使用剩余高度
- r - 如何在不耗尽内存的情况下将一长串事物与另一长串事物进行比较?