Heliton Martins
Heliton Martins

Reputation: 1221

Unhandled promise rejection: undefined is not an object (evaluating _expoLocation.requestForegroundPermissionsAsync)

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:

Platform info (after expo upgrade):

Upvotes: 2

Views: 1848

Answers (1)

Mouad Tahir
Mouad Tahir

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

Related Questions