I'm trying to get the user location in React Native with Expo (Managed Workflow for Android) following the official example for expo-location. Here is my function:
import Location from 'expo-location';
const handleLocationFinder = async () => {
const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
console.log('Permission denied. Enter the location manually.');
return;
}
const location = await Location.getCurrentPositionAsync({});
console.log(location);
};
However, when I call this function, I get this warning:
[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_expoLocation.default.requestForegroundPermissionsAsync')]
What I tried:
- Reinstall the app in the emulator;
- Fresh emulator;
- My actual phone (Android 8.0);
- Add
"permissions": ["ACCESS_FINE_LOCATION"]toapp.json(although expo seems to do this); expo upgrade;- Pray.
Platform info (after expo upgrade):
- Android 11.0 (Pixel 4 emulated)
expo: 41.0.1react-native: sdk-41.0.0expo-location: 12.0.4