javascript - RNLocation 包问题:subscribeToLocationUpdates 有时永远不会触发,有时它会自动开始工作
问题描述
getLatestLocation() 返回 null 并且 subscribeToLocationUpdates 永远不会触发:
import RNLocation from 'react-native-location';
RNLocation.requestPermission({
ios: 'whenInUse',
android: {detail: 'coarse'},
}).then((granted) => {
if (granted) {
RNLocation.getLatestLocation().then((loc) => {
Alert.alert(JSON.stringify(loc)); // <--- this returns null
});
RNLocation.subscribeToLocationUpdates((locations) => { // <-- this never fires
const {latitude, longitude} = locations[0];
Alert.alert(`${JSON.stringify({latitude, longitude})}`);
});
}
});`
解决方案
您可以通过将 android: 从粗略更改为精细的详细信息值来解决此问题。现在它按预期工作。
android: {detail: 'fine'},
希望这能解决你的问题
推荐阅读
- java - 服务层和控制器中的代码分离
- windows - 用于自动解锁用户帐户的 Eventviewer eventid
- android - react-native ios app webview在屏幕关闭时播放静音
- java - 空参数错误计算节点上的 id
- python - 模块内的变量范围
- json - Firebase 实时数据库验证数组中的子对象
- react-router-v4 - 使用connected-react-router在每次路由更改时更改的“关键”是什么?
- jax-rs - Glassfish/Payara 中带有 Singleton 的 jax-rs sse 客户端
- c++ - 如何将一对向量中一对的第一个元素(字符串)与另一个字符串进行比较?
- jdbc - 未加载 Logstash 'com.mysql.jdbc.Driver'