gpt4 book ai didi

android - 如何修复 [未处理的 promise 拒绝 : Error: Location provider is unavailable. 确保已启用位置服务。]

转载 作者:行者123 更新时间:2023-12-04 04:00:59 26 4
gpt4 key购买 nike

我刚刚将我的应用程序从 Expo SDK 37.0.0 升级到 38.0.0。该应用程序在 iOS 上运行良好,但在 Android 上我收到以下警告,并且该应用程序没有在 map 上对我进行地理定位。
开发环境:

  • Expo SDK 38.0.0(托管工作流)
  • react 原生 0.62
  • map 提供商:Android 上的 Google map
  • react 原生 map :0.27.1
  • react :16.11.0
  • 设备:荣耀8X/Android 10

  • 预期结果:应用程序应根据我的位置对我(用户)进行地理定位。
    实际结果:该应用程序不会根据我的位置对我(用户)进行地理定位。
    警告 :

    [Unhandled promise rejection: Error: Location provider is unavailable.Make sure that location services are enabled.]


    到目前为止我尝试了什么?
  • 再次运行 expo upgrade 以确保您的所有软件包都设置为正确的版本。
  • 删除 package-lock.json 和 node_modules 并运行 npm install。
  • 设置 Location.getCurrentPositionAsync({accuracy:Location.Accuracy.High})
  • 设置 Location.getCurrentPositionAsync({ enableHighAccuracy: true })
    import * as Location from 'expo-location';
    import * as Permissions from 'expo-permissions';


    async _getLocationAsync() {
    let { status } = await Permissions.askAsync(Permissions.LOCATION);
    if (status !== 'granted') {
    /* If user hasn't granted permission to geolocate himself herself */
    Alert.alert(
    "User location not detected",
    "You haven't granted permission to detect your location.",
    [{ text: 'OK', onPress: () => console.log('OK Pressed') }]
    );
    }

    let location = await Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.High });
    this.setState({
    userLat: location.coords.latitude,
    userLng: location.coords.longitude,
    navGeoStatus: true,
    lat: location.coords.latitude,
    lng: location.coords.longitude
    });
    }```
  • 最佳答案

    如果有人仍在与此问题作斗争 - 请检查您是否添加了:

     "android": {
    "permissions": ["ACCESS_BACKGROUND_LOCATION"]
    },
    在您的 app.json文件

    关于android - 如何修复 [未处理的 promise 拒绝 : Error: Location provider is unavailable. 确保已启用位置服务。],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63060617/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com