Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have just upgraded my app from Expo SDK 37.0.0 to 38.0.0. The app works fine on iOS but on Android I get the following warning and the app doesn't geolocate me on the map.

Development environment :

  • Expo SDK 38.0.0 (managed workflow)
  • React Native 0.62
  • Maps provider : Google Maps on Android
  • react-native-maps: 0.27.1
  • React: 16.11.0
  • Device : Honor 8X/Android 10

Expected result : The app should geolocate me (the user) based on my position. Actual result : The app doesn't geolocate me (the user) based on my position. Warning :

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

What have I tried so far?

  1. Ran expo upgrade once more to ensure that all of your packages are set to the correct version.

  2. Deleted package-lock.json and node_modules and ran npm install.

  3. Set Location.getCurrentPositionAsync({accuracy:Location.Accuracy.High})

  4. Set 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
      });
    }```
    
like image 277
Sujay Avatar asked Jul 23 '20 18:07

Sujay


1 Answers

If anyone is still fighting with this problem - please check if you have added:

 "android": {
  "permissions": ["ACCESS_BACKGROUND_LOCATION"]
},

in your app.json file

like image 96
Bartek Avatar answered Nov 13 '22 12:11

Bartek