Error on Location.startLocationUpdatesAsync
See original GitHub issueš Bug Report
Summary of Issue
Impossible to start background location updating. Getting this error:
Unhandled promise rejection: Error: Not authorized to use background location services.
Environment - output of expo diagnostics & the platform(s) youāre targeting
Expo CLI 4.0.12 environment info:
System:
OS: Windows 10 10.0.19041
Binaries:
Node: 14.15.1 - E:\PHP\laragon\bin\nodejs\node-v14\node.EXE
Yarn: 1.21.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.8 - E:\PHP\laragon\bin\nodejs\node-v14\npm.CMD
IDEs:
Android Studio: Version 4.0.0.0 AI-193.6911.18.40.6626763
npmPackages:
expo: ^40.0.0 => 40.0.0
react: 16.13.1 => 16.13.1
react-dom: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-40.0.0.tar.gz => 0.63.2
react-native-web: ~0.13.12 => 0.13.18
Expo Workflow: managed
Reproducible Demo
const LOCATION_TRACKING = 'background-location-tracking';
export default class App extends Component
{
componentDidMount() {
this.locationTracking();
}
locationTracking = async () => {
const { status } = await Location.requestPermissionsAsync();
if (status === 'granted') {
let location = await Location.startLocationUpdatesAsync(LOCATION_TRACKING, {
accuracy: Location.Accuracy.BestForNavigation,
showsBackgroundLocationIndicator: true,
timeInterval: 30000,
activityType: Location.ActivityType.AutomotiveNavigation,
distanceInterval: 1
});
}
}
}
TaskManager.defineTask(LOCATION_TRACKING, async ({ data, error }) => {
if (error) {
console.log('LOCATION_TRACKING task ERROR:', error);
return;
}
if(data) {
const { locations } = data;
console.log('send to api');
}
});
Steps to Reproduce
Just use to code.
Expected Behavior vs Actual Behavior
To not get the error. When trying to debug status i get granted.
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (6 by maintainers)
Top Results From Across the Web
Location.startLocationUpdatesAsync is not a function error
SDK Version: āexpoā: ā~40.0.0ā; Platforms(Android/iOS/web/all): all. I was having an issue with TaskManager + startLocationUpdatesAsync inĀ ...
Read more >startLocationUpdatesAsync is not working on the background ...
I'm trying to track my user location when the application is in the background, it works fine in the foreground and the notification...
Read more >How to use the expo-location.getCurrentPositionAsync ... - Snyk
To help you get started, we've selected a few expo-location.getCurrentPositionAsync examples, based on popular ways it is used in public projects.
Read more >expo-location | Yarn - Package Manager
Allows reading geolocation information from the device. Your app can poll for the current location or subscribe to location update events.
Read more >How to keep update location even the object not moving using ...
Coding example for the question How to keep update location even the object not moving using expo background service Location.startLocationUpdatesAsync()Ā ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Last update š
Deployment
2.18.5is released to production, you can install it through$ expo client:install:android.$ expo build:android.How to use it
2.18.5+and build a new standalone app.expo-locationwith the native code changes ASAP. Unfortunately, we have to check some differences out first. Meanwhile, you can use something likepatch-packageto include this changeturtle-clito0.20.5+Sample app
Android support
Happy holidays!
Hi people, I wanted to give a quick update on this issue for all of you. Itās unfortunate that Google is rapidly changing the permissions around locations. Thanks to @peterdn, we have a fix ready for Android <9. Android 10 works as expected, but for Android 11 we need to do more testing and possibly refactoring. Here is why:
Android <9 On this version of Android, background permission was similar to foreground permission. When asking permission for
ACCESS_COARSE_LOCATIONand/orACCESS_FINE_LOCATION, you already received access to fetch the location in the background.ACCESS_BACKGROUND_LOCATIONdoesnāt exist in this version and should not be requested to users (see this, added in API 29/Android 10). Thatās why this is excluded when requesting permission forLOCATIONin Android, throughPermissions.askAsync(Permissions.LOCATION).Android 10 This version of Android includes the new
ACCESS_BACKGROUND_LOCATIONpermission, which used to be auto-requested in Expo. Because Googleās policy is now more āaggressiveā against apps that request this permission (because of the additional audit), we made it an opt-in. Right now, the code is handling this properly, throughPermissions.askAsync(Permissions.LOCATION).Android 11 The latest version of Android includes another change related to the location. We canāt request both āforegroundā and ābackgroundā location at the same time. It also āremovesā the option for users to āallow location access all the timeā from the permission dialog and puts this under the settings (you can see the screens below). This is something to be aware of when creating your app.
Iāll create an example app that uses the background location permission and link the source here. That app should be published on the Play store, but I canāt estimate right now how long that will take. Once I have more to share, I will keep you updated.
Android 11 Location permission screens