TALHA001
TALHA001

Reputation: 151

Expo App not showing popup for Location Permission

In my expo app I want to get a user's location I am trying the same code as on the official website of Expo for getting User's location. But expo app is not showing popup for location permission, please see the code below,

componentWillMount() {
this._getLocationAsync();
}

_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.CAMERA);
if (status !== 'granted') {
  this.setState({
    errorMessage: 'Permission to access location was denied',
  });
}

// let location = await Location.getCurrentPositionAsync({});
// this.setState({ location });
};

On the other hand if I replace Permissions.LOCATION with Permissions.CAMERA the app shows popup for permission.

Please help I am unable to solve this issue I am using android device

Upvotes: 0

Views: 2496

Answers (1)

sinan
sinan

Reputation: 570

First componentWillMount is deprecated. Try it with componentDidMount

Second you may already gave location permission to app. Check settings on the phone if permission is already provided. If yes, change it on the settings and try again.

componentDidMount() {
this._getLocationAsync();
}

_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.CAMERA);
if (status !== 'granted') {
  this.setState({
    errorMessage: 'Permission to access location was denied',
  });
}

// let location = await Location.getCurrentPositionAsync({});
// this.setState({ location });
};

Upvotes: 1

Related Questions