- SDK Version: 39
- 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,
},
});