expo: [Unhandled promise rejection: Error: Location provider is unavailable. Make sure that location services are enabled.]
I have just upgraded my app from Expo SDK 37.0.0 to 38.0.0. The app works fine on iOS but on Android I get the following warning and the app doesn’t geolocate me on the map. On Expo SDK 37 this feature was working perfectly fine.
Expected result : The app should geolocate me (the user) based on my position. Actual result : The app doesn’t geolocate me (the user) based on my position. The problem is specific to Android. On iOS this feature works fine. Warning :
[Unhandled promise rejection: Error: Location provider is unavailable. Make sure that location services are enabled.]
Development environment :
- Expo SDK 38.0.0
- React Native 0.62
- Maps provider : Google Maps on Android
- react-native-maps: 0.27.1
- React: 16.11.0
- Device : Honor 8X/Android 10
What have I tried so far ?
- Ran expo upgrade once more to ensure that all of my packages were set to the correct version.
- Deleted package-lock.json and node_modules and ran npm install.
- Set Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.High })
- Set Location.getCurrentPositionAsync({ enableHighAccuracy: true })
- Set Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.Lowest })
- Set Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.Low })
- Set Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.Balanced })
- An upgrade to Expo SDK 39.0.0 shows no improvement. The error is the same.
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';
async _getLocationAsync() {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
/* If user hasn't granted permission to geolocate himself herself */
Alert.alert(
"User location not detected",
"You haven't granted permission to detect your location.",
[{ text: 'OK', onPress: () => console.log('OK Pressed') }]
);
}
let location = await Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.High });
this.setState({
userLat: location.coords.latitude,
userLng: location.coords.longitude,
navGeoStatus: true,
lat: location.coords.latitude,
lng: location.coords.longitude
});
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 61 (8 by maintainers)
Hello I was reading all this feed because a I was facing the same issue. However, As experiment, I set
Location.getCurrentPositionAsync({accuracy: 6})and suddenly start to work properly. Let me know if this solutions works for someone else.Happens randomly for me on a low-end Android 10 (go edition) phone, using Expo SDK 41. This ugly workaround does the job for me:
Fails a random amount of times before getting out of that while block, from 1 if lucky to 20+ in my tests. Frustrating, but at least your app will eventually work if it depends on location.
Fun fact: I put an activity indicator to appear until that while block is resolved, sometimes it appears for 1 second but other times it can stay for a several minutes. When this happens, I enable airplane mode on the phone, then disable it immediately, go back to the app and location is resolved.
I’ve tried all of the solutions in this thread, and I’m still receiving the error.
Update: Using Location.getLastKnownPositionAsync(options) is a good temporary fix, but Location.getCurrentPositionAsync() isn’t working.
I was able to get around this issue by replacing
const { status } = await Permissions.askAsync(Permissions.LOCATION);withconst { status } = await Location.requestPermissionsAsync();Hopefully this works for everyone else.that solved my problem:
apparently the method “getCurrentPositionAsync” should return null when not finding location but is returning an exception without respecting the timeout.
Finally it works doing this
https://github.com/expo/expo/issues/5504#issuecomment-905988820
Yesterday, before I sleep, my app was working perfectly but now It’s throwing the same error. And I didn’t even change my code since yesterday. Tried all aboe and none of it worked.
watchPositionAsync()working as expected also. Something wrong withgetCurrentPositionAsync().@enesakin1 Same issue on a variety of Android devices
Same problem for me, @enesakin1. My app is on the play store and worked great a day ago, now none of my users with Android can use it…
I did notice that it works fine if I’m using an app like “Fake GPS” to spoof my location, I’m not sure if that information will help anyone solve this but I hope it does.
If this bug is corrected in SDK 41, it will be a huge relief for me.
FYI: https://github.com/expo/expo/issues/14248#issuecomment-915099538
@enesakin1 Having same problem with redmi note 8.
Ahh ok, I see. Thanks for explanation. My app requires regular monitoring of the user’s position. We are still in MVP state, but I will investigate this case related to Google Play Store, didn’t know about it.
Hello @BartekH , Thanks for sharing your solution. The problem is that ACCESS_BACKGROUND_LOCATION is allowed only for apps that require a continuous/regular monitoring of the user’s position like food delivery, navigational/driving apps. Unless you can justify that your app requires continuous monitoring of the user’s position, Google Play Store will not approve the app. They implemented this policy change roughly sometime during the summer of 2020.
Could you please tell me that your app was approved/deployed on Google Play Store and that it is not an app that requires continuous monitoring of the user’s position ?
I tried this and my app was rejected by Google Play Store during deployment because my app doesn’t require a continuous/regular monitoring of the user’s position.
Thanks for your help. Warm regards.
const { status } = await Permissions.askAsync(Permissions.LOCATION);andconst { status } = await Location.requestPermissionsAsync();are both working. The problem is that
let location = await Location.getCurrentPositionAsync({});is not returning a promise resolving to an object of type LocationObject. I have tried passing in options as well aslet location = await Location.getLastKnownPositionAsync();without any success. Nevertheless, thanks for sharing your solution. It might help someone. But my problem is still intact.