Skip to main content
By the end of this guide, your app will start a trip when a journey begins, your backend will receive a live ETA and approaching and arrival events, and tracking will return to its earlier state when the journey ends. The guide follows an order pickup, then shows what changes for deliveries and workers.

Complete example

This is the client side of a pickup: initialize, identify the user, request permission, start a trip to the store’s geofence with continuous tracking, receive approaching and arrival events, and complete or cancel the trip.
The web SDK has no background tracking, so the JavaScript tab sends a location on a timer while the page is open. The React Native tab uses React Native SDK 4.39.0, which passes trackingOptions to startTrip(). While a trip is active, the user’s context includes it, with eta.duration in minutes and eta.distance in meters:

Prerequisites

  • A destination geofence for each place a trip can end. See Create geofences.
  • Foreground location permission. A trip that uses the continuous preset doesn’t need background permission. See location permissions.
  • On iOS, the Location updates and Background fetch background modes. On Android, the foreground service declared in your manifest. See the iOS SDK and Android SDK references.
  • A stable ID for each journey, such as an order ID, and one for the user. See Handle login, logout, and user switching.
  • An HTTPS endpoint for webhooks, so that your backend receives trip events.

Track pickups

A customer orders ahead and travels to one of your locations, and the order needs to be ready when they arrive. Use the order ID as the trip externalId, the store ID as the destination geofence externalId, and trip metadata for handoff details such as a parking space. In the Trips section of the Settings page, turn on the trip event types you consume. Set Approaching threshold (minutes), the ETA at which a trip becomes approaching, to the notice the store needs. Set Expiration, the number of hours after which a trip that nobody ended is ended automatically. Test and Live have separate settings.

Start the pickup trip

Call Radar.startTrip() when the journey begins. For an order the customer wants as soon as possible, that is when the order is confirmed. For a scheduled order, wait until the customer taps “I’m on my way”. Otherwise a customer at home five minutes from the store is already below the approaching threshold, and the order is prepared far too early. Starting a trip is a network request, so disable the button that starts it until the callback returns. If the call fails, keep the order on its time-based path. If your orders run through Olo, see Olo pickup and order firing. Your backend can also create a trip with Create a new trip, but the device still has to be sending locations for the trip to progress.

Choose tracking options for trips

Pass the continuous preset to startTrip(). It sends an update about every 30 seconds, and while the iOS location indicator or the Android foreground service is active, foreground permission is enough for the trip to keep updating in the background. If the SDK was already tracking, it remembers the earlier options and restores them when the trip ends. To change on-trip options without an app release, see On-trip tracking options. For preset values, see Tracking options.

Trip events

A trip’s status is started, approaching, or arrived while it is active, and completed, canceled, or expired when it ends. A trip created through the Trips API can also be pending. Receive trip events in the app with the delegate or receiver in the complete example, and on your backend by webhook. There, look up the order by trip.externalId and deduplicate on event._id.

Prepare the order from ETA and arrival, with a time-based fallback

Location improves timing when it is available. It must never be the only thing that gets an order made, because a force-quit app, a phone that is off, or a denied permission produces no updates. Decide the latest time at which preparation must start, schedule a fallback for it, and start preparing at whichever comes first. This is the backend logic in pseudocode:
Both paths lead to the same “start preparing” action, which must be safe to call twice. A customer who starts the trip while already at the store can go from started straight to arrived. When your app knows the customer has arrived before Radar detects it, for example from an “I’m here” button, update the trip. This example adds a parking space and moves the trip to arrived:

Stopping trips

End every trip explicitly. Call completeTrip() at handoff, not at arrival, and cancelTrip() when the order is canceled. When either call returns, the SDK restores the tracking options that were running before the trip, or stops tracking if it wasn’t tracking before. On iOS and Android, don’t call Radar.stopTracking() after a trip unless you want all tracking off, including background tracking that was running before the trip. If the call fails with anything other than a not-found status, for example with no network, the trip is still active on the server. Retry, or end the trip from your backend with Update a trip. A trip that nobody ends becomes expired.

Recover on app open and resume

Trip state lives on Radar’s servers and tracking state lives on the device. They drift apart when the user force-quits the app, the device restarts, or the trip ends on the server while the app is closed. Each time the app opens or returns to the foreground, call trackOnce() and read user.trip:
A force-quit app doesn’t track until the user opens it again, which is why the time-based fallback exists.

Track deliveries

Here the tracked device belongs to the traveler: a driver going to one or more customer addresses. The lifecycle is the same as a pickup, with these differences:
  • Identity: Call Radar.setUserId() with the driver’s ID at sign-in, and use the delivery or route ID as the trip externalId.
  • Destination: A customer address usually isn’t a geofence you already have. Create one from your backend when the job is created, with Upsert a geofence, and set deleteAfter so that it deletes itself afterwards.
  • End: Complete the trip when the driver confirms the drop-off, and cancel it if the job is reassigned.
  • Customer-facing ETA: Store the latest trip.eta from user.updated_trip webhooks for each trip.externalId, and serve it from your backend. The Trips API needs a secret key, so never call it from a customer’s browser or app.

Multi-leg trips

Multi-leg trips must be enabled for your project. Contact your Radar account team.
A multi-leg trip is one trip with an ordered list of stops. Each leg has its own destination (a geofence, an address, or coordinates), status, ETA, and metadata, and the trip has a currentLegId. For address and coordinate destinations, set arrivalRadius, in meters. Set stopDuration, in minutes, so that the ETAs of later legs account for time spent at each stop. This example starts a three-stop route with the native SDKs:
When the driver finishes a stop, call Radar.updateCurrentTripLeg() with the status completed. Radar starts the next leg, and completing the final leg completes the trip. Radar follows the leg order you give it. To change the order during the route, call Radar.reorderTripLegs(). See Trip legs.

Track workers

Here you track people for a work period instead of for one journey: field service, home health, or shift work at changing sites. A trip still covers the journey to a job site. Around it, your app switches tracking on at clock-in and off at clock-out.
  • Clock in: Start tracking with the responsive preset, which needs background location permission.
  • Journey to a site: Start a trip to the site geofence, as in a pickup. When you complete it, the SDK restores on-clock tracking, so don’t call stopTracking().
  • Arrival and departure: On your backend, use user.entered_geofence and user.exited_geofence for the site geofence. The exit event’s duration is the time on site in minutes.
  • Clock out: End any active trip first, then stop tracking, because ending a trip restores the tracking that was running before it.
This example shows clock-in and clock-out:
The SDK doesn’t run your code at a wall-clock time. Your code runs when the app is opened and when a location update is delivered. With tracking off and the app not running, tracking can’t start at the exact moment a shift begins. It resumes when the worker opens the app or clocks in. To switch at shift boundaries without a tap, keep a low-frequency mode such as the efficient preset running off the clock, and compare the intended mode with the active one on each location update. That collects location outside working hours, which you must disclose. If payroll depends on exact times, take them from the worker’s clock-in action or from geofence events, not from the moment tracking changed.

Update a Live Activity from trip state

On iOS, a Live Activity can show trip progress on the Lock Screen. Radar doesn’t create or update Live Activities. Your app does, with ActivityKit. Update the activity from didUpdateLocation(_:user:), which carries the current trip on every update, and end it when user.trip is absent or a user.stopped_trip event arrives. Set a staleDate, because updates stop when the app is suspended or force-quit.

Handle results and errors

Test the integration

  • Passing case: In the Test environment, start a trip, then call Radar.mockTracking() on iOS or Android toward the destination geofence. The Events page shows user.started_trip, user.updated_trip with a falling ETA, user.approaching_trip_destination, and user.arrived_at_trip_destination. Complete the trip, and tracking returns to its earlier state.
  • Failing case: Start a trip, then force-quit the app. No further updates arrive, preparation starts at the fallback time, and reopening the app restores the trip UI and tracking.
Before launch, run one real journey on a physical device with the screen locked. See Test, troubleshoot, and go live.

Production checklist

  • Destination geofences, the approaching threshold, and expiration are set in Live.
  • Every way out of a journey ends the trip: handoff, cancellation, reassignment, sign-out.
  • Continuous tracking runs only during a trip.
  • The app reconciles trip and tracking state on open and on resume.
  • A time-based fallback covers journeys that never report a location.
  • iOS background modes and the Android foreground service declaration are in place.

Build with an agent

Copy this prompt into a coding agent that has access to your repository.

See also