Enable Location Services automatically

Hi everyone!

For the case when Location.hasServicesEnabledAsync() returns false I would like to prompt the user with a modal saying that the location services need to be enabled and when the user taps an OK button to automatically turn on the Location services - like it happens in the Uber app for example.
Is there any way to achieve this? While researching a way to do this I saw on some pull request Location.enableNetworkProviderAsync() - could this be a solution and if so where can I find more details about it?

Thank you for a reply! :slight_smile:

Hi @flavia!

Have you already taken a look at the Expo Permissions API? You can request permission for location services using that.

I’m not sure if this answers your question, so let me know!

Hi @charliecruzan!

Yes I am using that as well and it works for the case when I have location services enabled manually, but I still would like to be enable Location services automatically, here’s what I am doing:

let servicesEnabled = await Location.hasServicesEnabledAsync();
if (!servicesEnabled) {
//want to enable
alert(‘You need to enable location services on your device’);
return;
}
let {status} = await Permissions.askAsync(Permissions.LOCATION);
if (status !== ‘granted’) {
alert(‘you need to grant location permissions’);
return;
}

//after this I am doing
let region = await Location.getCurrentPositionAsync({});

If I do just await Permissions.askAsync(Permissions.LOCATION); I get an error with the message Location services are disabled.

Is there something I am missing?

Thank you!
Flavia

Ah okay. No, you need to get explicit permission from the user to access their location, I don’t believe there’s any way to enable it automatically without prompting.

Yes, I want to implement a modal with an OK button to ask the user to enable location and when the user taps on OK I want to be able to enable location services such that the user doesn’t have to. Is this possible?

Thank you!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.