【问题标题】:Listen the status of location service with React Native Expo (not permissions)使用 React Native Expo 监听定位服务的状态(不是权限)
【发布时间】:2020-06-14 13:35:20
【问题描述】:

假设用户使用的地图要求该位置处于活动状态,如果没有,则该地图将被关闭。

有什么方法可以使用 Location.hasServicesEnabledAsync() 监听 Location 状态吗?

【问题讨论】:

  • 我认为目前没有这样的听众。我建议在几秒钟内未收到位置更新后检查hasServicesEnabledAsync。您可以通过在每次位置更新时重置递归超时来实现这一点。

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


【解决方案1】:

合作:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-09
    • 2023-03-22
    • 1970-01-01
    • 2018-06-11
    • 2018-08-04
    • 2021-06-22
    • 1970-01-01
    • 2021-04-04
    相关资源
    最近更新 更多