Location.startLocationUpdatesAsync and foregroundService are not working as expected

See original GitHub issue

🐛 Bug Report

Environment

Expo CLI 2.19.4 environment info: System: OS: macOS 10.14.4 Shell: 3.2.57 - /bin/bash Binaries: Node: 10.15.3 - /usr/local/bin/node Yarn: 1.13.0 - /usr/local/bin/yarn npm: 6.4.1 - /usr/local/bin/npm IDEs: Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild npmPackages: expo: ^33.0.0 => 33.0.5 react: 16.8.3 => 16.8.3 react-native: https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz => 0.59.8 react-navigation: ^3.11.0 => 3.11.0 npmGlobalPackages: expo-cli: 2.19.4

My target platform is Android. I am using expo SDK version 33. (This is reproducable in SDK 32 also)

Steps to Reproduce

Download this snack, it only works on a real phone (you can’t reproduce this with simulated/fake locations, and android emulators).

Run the app, and then navigate away from it in the os. Now when you go back, an alert should appear that shows how many location updates occured while the app was in the background state.

Expected Behavior

The application, should recice at least some location updates while in the background, and this should be aligned with the arguments passed to the Location.startLocationUpdatesAsync function. When using the new foregroundService atribute, the app should get location updates as frequently as if it was in the foreground state.

Actual Behavior

This is not the case, for a real device and real locations, you do not get any updates, the alert always shows 0 no mater how far you go. However you will recieve location updates if you use some kind of simulated/mock/fake location. (It does not matter if you create a foregroundService or not, and this is reproduceable in a standalone app too, not just the expo client! )

Reproducible Demo

The snack is here, you should download it and run it on a real device.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
esistgutcommented, Jun 24, 2019

I get it when compiling the app as stand alone. Doesn’t show up when running it in the Expo client.

2reactions
grenadejumpercommented, Jun 13, 2019

I could have sworn I saw a fix for this merged after the release of the latest 32-version, but I can’t find the issue atm. Was expecting this to work in 33, but I am unfortunately having the same issue as @Dewyer : my app stops updating the background location as soon as I lock my phone or switch to another app.

Perhaps I/we are using it incorrectly? It would be nice if the documentation could be updated with information on how to get background location updates working. For instance: I can’t find anything about the property foregroundService (if it is indeed a valid property for Location.startLocationUpdatesAsync.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Location - Expo Documentation
Stops geofencing for specified task. It unregisters the background task so the app will not be receiving any updates, especially in the background....
Read more >
Inconsistent location updates in foreground service when in ...
I'm using a foreground service that requests a location update with high ... Also these issues are inconsistent from one version of Android...
Read more >
How to keep update location even the object not moving using ...
[Solved]-How to keep update location even the object not moving using expo background service Location.startLocationUpdatesAsync(),-React Native.
Read more >
Getting background location updates for a driver like app?
But I'm not sure how does it work behind the scene. ... startLocationUpdatesAsync(LOCATION_TASK, { foregroundService: { notificationBody: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found