所以我正在尝试制作一个天气应用程序,当我在弹出窗口中拒绝(按NO(以启用位置时,它会给我以下错误:[Unhandled promise rejection: Error: Location request failed due to unsatisfied device settings.]
代码的重要部分如下所示。
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permission to access location was denied, please activate location and reopen the app.',
});
}
let location = await Location.getCurrentPositionAsync({enableHighAccuracy:true});
let lat = location.coords.latitude;
let lon = location.coords.longitude;
注意:我使用的是react native的最后一个版本,我在安卓系统上,我使用了expo位置,当我启用(按YES(位置时,它非常有效。
您应该用try-catch块包装等待调用,以捕获错误。
try {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
} catch(err) {
//handle err
}