Skip to main content
Native Plugins & Integrations1 min read

Background Location

Track location continuously, also while the app is in the background, and send points to your server, with the Background Location plugin.

Overview

The Background Location plugin tracks location continuously, also while the app is in the background, and sends the points to your server. Typical uses are delivery, field service and fitness apps. For location while the app is open, Location Services is enough.

Turn it on in Integrations › Native plugins and build a new version. Changing the location access mode or permission texts needs another build.

Location access

whenInUse (default)always
Tracking you start in the appkeeps running in the backgroundkeeps running in the background
Can start in the background, after a restartnoyes
iPhoneblue location indicator while runningasks for "Always" access
Store reviewGoogle Play: declare the location foreground serviceGoogle Play: background-location declaration with a video; Apple asks why "Always" is needed

Use whenInUse unless tracking must start without the user opening the app. On Android a notification is always shown while tracking runs (Android requires it); set its title and text in the plugin settings.

Send points to your server

javascript
await wapp.backgroundLocation.start({
  postUrl: 'https://example.com/api/locations',
  postHeaders: { Authorization: 'Bearer ' + sessionToken },
  androidInterval: 30000,   // ms
  iosDistanceFilter: 25,    // meters
});

Your server receives POST { "locations": [ { timestamp, latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy, speed, bearing } ] } in batches of up to 100, also in the background.

  • Points are saved on the phone first and sent later if your server is down or the app is closed.
  • Use postHeaders for authentication: cookies are not sent from the background, and tokens in URLs end up in server logs.

Or receive points on your page

Without postUrl, points arrive on the page while the app is open; points from the background arrive in one batch when the user comes back.

javascript
wapp.on('background_location', (data) => drawTrack(data.locations));
await wapp.backgroundLocation.start({});

Stop and check

javascript
await wapp.backgroundLocation.stop();
const status = await wapp.backgroundLocation.status(); // { running, mode, delivery, queued, permission }

Options

  • iPhone: iosDesiredAccuracy, iosDistanceFilter, iosActivityType, iosPauseAutomatically, iosBackgroundIndicator.
  • Android: androidPriority (highAccuracy, balanced, lowPower, passive), androidInterval, androidFastestInterval, androidSmallestDisplacement, androidNotificationTitle, androidNotificationText.

Next steps