Tracking user location with TaskManager and sending data to an API?

Hello!

First of all, here is a short brief of our assignment: we need to enable background location tracking when a user taps on a button and then send that location data to an API with roughly one minute intervals. Every given POST should contain the users ID, location data, and the state that the user is in, i.e ‘working’, ‘on a break’, etc.

Location.startLocationUpdatesAsync is currently working, we are getting the data and can send it to the API just fine – but only while the app is in the foreground, since the fetch part lives inside of the app and not in the TaskManager function. And while the background function can see the location data, we have not been able to find a way to pass the users ID and state to it. Is it even possible to pass custom data to a background task?

The only solution, that we could currently come up with, is to send our required data to the API by just using KeepAwake and telling the user not to hide our app. Keep in mind that in the context of our app, it is in the users own best interest that this data gets sent. Ideally we would still like to send it in the background task to minimize any accidental “outages” :slight_smile:

Does anyone have any ideas how this could be done? Is it even possible without ejecting?

Hey @infrafly,

I recommend using Expo’s Background Fetch API.

Good luck!

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