简体   繁体   English

使用 React Native Expo 监听定位服务的状态(不是权限)

[英]Listen the status of location service with React Native Expo (not permissions)

Imagine that the user is using a map that requires the location to be active, and if not, the map will be closed.假设用户正在使用要求该位置处于活动状态的 map,如果没有,则 map 将被关闭。

Is there any way to listen to the Location status using Location.hasServicesEnabledAsync()?有没有办法使用 Location.hasServicesEnabledAsync() 来监听位置状态?

Working with:与:

_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);
         }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM