Reputation: 1221
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:
"permissions": ["ACCESS_FINE_LOCATION"]
to app.json
(although expo seems to do this);expo upgrade
;Platform info (after expo upgrade
):
expo
: 41.0.1react-native
: sdk-41.0.0expo-location
: 12.0.4Upvotes: 2
Views: 1848
Reputation: 510
I got the same issue and when i changed:
import Location from "expo-location";
To:
import * as Location from "expo-location";
Like what in the documentation, it worked for me.
Upvotes: 4