SDK 39, Android + Location issue.

  1. SDK Version: 39
  2. Platforms(Android): 8 (using physical device)

I create a new app using and the code from: https://docs.expo.io/versions/latest/sdk/location

I keep getting the error: [Unhandled promise rejection: Error: Location provider is unavailable. Make sure that location services are enabled.]

I have tried using the exact code from the API Reference Documentation Location page detailed above and also have tried setting all levels of location accuracy (from Lowest to BestForNavigation) without success.

I confirm location is enabled on the physical device.

I have also tried returning and handling the promise and I get the same error.

To test on a blank project use the code from the documentation or as follows:

import React, { useState, useEffect } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import * as Location from 'expo-location';

export default function App() {
  const [location, setLocation] = useState(null);
  const [errorMsg, setErrorMsg] = useState(null);

  useEffect(() => {
    (async () => {
      let { status } = await Location.requestPermissionsAsync();
      if (status !== 'granted') {
        setErrorMsg('Permission to access location was denied');
      }

      let location = await Location.getCurrentPositionAsync({});
      setLocation(location);
    })();
  }, []);

  let text = 'Waiting..';
  if (errorMsg) {
    text = errorMsg;
  } else if (location) {
    text = JSON.stringify(location);
  }

  return (
    <View style={styles.container}>
      <Text>{text}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

I have the same problem

What version of Android OS are you using?

i’m using my real device with android 10.
I solved the problem by just reinstalling expo on the device.

sorry for my English

1 Like

Thanks for the reply, I’m pleased it works for you now. I’m using real device with Android 8 and reinstalling Expo did not solve this for me :worried:

Does it work for you using the code I posted above (exact code from Expo documentation) or did you change anything?

Thanks.

I tested your code and it worked.
Did you test the code on the Android emulator?

1 Like

Yes emulator and physical device. I’ll try resetting the device/factory reset and install Expo again and see if that solves the issue.

Many thanks for testing the code.

Did you add anything for Android in app.json?

Thanks again.

No, I created a new expo project, added the expo-location and pasted your code.

what’s your version of expo-cli? i’m using the last version (3.27.12).

1 Like

Hi again, I had previously uninstalled/reinstalled Expo on the device without success.

Thanks for the replies as once I knew you had the same issue and solved it I went ahead and did the factory reset and now it is working fine :grinning: :+1: :+1: :+1:

1 Like

If anyone else has this issue I recommend doing what I did and @caduvgomes and uninstall/reinstall Expo and also it’s worth checking you have the most recent expo-cli also.

I’m not sure if there is cached data/settings on an Android device however it worked for me after a factory reset.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.