使用React Native Expo监听位置服务的状态(非权限)

时间:2020-06-14 13:35:20

标签: javascript reactjs react-native react-redux expo

假设用户使用的地图需要该位置处于活动状态,否则,该地图将被关闭。

是否可以使用Location.hasServicesEnabledAsync()监听位置状态?

1 个答案:

答案 0 :(得分:0)

使用:

_getLocationAsync = async () => {
    let { status } = await 
Permissions.askAsync(Permissions.LOCATION);
    if (status !== 'granted') {
        alert('The request was denied');
    }else{
        try{
            let location = await Location.getCurrentPositionAsync({});
            // do something with location
         }catch(e){
            alert('We could not find your position. Please make sure your 
         location service provider is on');
            console.log('Error while trying to get location: ', e);
         }
    }
}