Real-time driver tracking without killing the battery

A moving car on the rider's map looks like the simplest feature in a ride-hailing app. In practice it is where mobile platform rules, GPS physics, battery life and privacy law all meet. This post walks through the decisions that matter, with small code sketches you can adapt.
The pipeline in one paragraph
The driver app reads the phone's location (a fusion of GPS, Wi-Fi and mobile network signals), sends position, time, speed, heading and accuracy to your server, the server keeps the latest point for matching and the full path for the fare, and it pushes each update to the rider following the trip and to the operations console. The rider app animates the car between updates so it glides along the road instead of jumping.
Everything interesting is in the details of each step.
1. Don't use one update interval
The most common mistake is a single fixed interval, often "every 2 seconds, always". A driver may be online for ten hours, and most of that time nobody is watching their dot on a map.
Tie the interval and accuracy to the trip state instead:
// Android, FusedLocationProviderClient (play-services-location 21+)
fun requestFor(state: DriverState): LocationRequest = when (state) {
DriverState.WAITING -> LocationRequest.Builder(Priority.PRIORITY_BALANCED_POWER_ACCURACY, 15_000)
.setMinUpdateDistanceMeters(50f) // a parked car sends nothing new
.build()
DriverState.TO_PICKUP, DriverState.ON_TRIP ->
LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 3_000)
.setMinUpdateDistanceMeters(5f)
.build()
DriverState.OFFLINE -> error("no tracking while offline")
}
The numbers are illustrative. What matters is the shape: sparse and coarse while waiting, frequent and precise while a rider is watching or a fare is being measured, and nothing at all while offline.
2. Respect the background location rules
The driver app must keep sending its location while the driver uses navigation or the screen is off, and both platforms restrict that:
- Android requires a foreground service with a visible notification while location runs in the background. Google Play asks apps that use background location to declare it and explain why, and may ask for a short video.
- iOS requires the background location mode and a clear explanation in the permission prompt, and App Review checks that the app really needs it.
- Only the driver app should ask for background location. A rider app needs location only while it is open, to set the pickup.
Getting this wrong is one of the most common reasons ride-hailing apps are rejected. There is a checklist of the declarations both stores expect in this guide to taxi app store approval.
3. Clean the GPS before you trust it
Raw GPS is noisy, especially between tall buildings and in tunnels. Three cheap filters remove most of the junk before it reaches the rider's screen or the fare:
// Server side: accept or drop an incoming point
const MAX_ACCURACY_M = 50; // drop low-quality fixes
const MAX_SPEED_MS = 70; // ~250 km/h: anything faster is a jump
function acceptPoint(prev: Point | null, p: Point): boolean {
if (p.accuracy > MAX_ACCURACY_M) return false;
if (!prev) return true;
if (p.ts <= prev.ts) return false; // out of order or duplicate
const dt = (p.ts - prev.ts) / 1000;
const speed = haversineMeters(prev, p) / dt;
return speed <= MAX_SPEED_MS;
}
Snapping the path to the road network makes the car follow streets and gives better distances, but it usually costs extra map API calls. Many apps snap only the finished trip path for the fare and receipt, not every live point.
4. Animate instead of sending more
If the car jumps every three seconds, the instinct is to send updates every second. Don't. Interpolating the marker between the last two points, using the reported heading for rotation, looks smoother than a faster update rate and costs nothing in battery or data. Push one update; let the rider's phone do the animation.
5. Push, don't poll
Each rider following a trip polling the server every second multiplies load by the number of watchers. Use a persistent channel (WebSockets or a managed pub/sub service) from the server to the rider app and the console, and fall back to push notifications only for state changes such as "driver arrived". On the driver side, batch points when the connection drops and send them when it returns, so the fare path has no gaps.
6. Treat location as personal data
Location is personal data under most privacy laws. A defensible default:
- collect driver location only while the driver is online;
- show a driver's position to a rider only during that rider's own trip;
- keep trip paths only as long as you need them for fares, disputes, safety reviews and legal retention rules;
- say all of this plainly in the privacy notice.
The same data is also a safety feature. Live trip sharing lets a rider send a link to a friend, and an SOS button can send the current position to the operations team.
7. Know where the money goes
Sending and storing location updates is cheap. The cost comes from map and routing services: maps in the apps, arrival times, routes, road distances and snapping. Those scale with every active trip, so compute ETAs once on the server and push them out, rather than calling a routing API from every rider's phone.
Summary
Good tracking is less about the map and more about discipline: interval by state, platform-compliant background location, filtered points, client-side animation, push channels and a clear privacy policy. There is a longer non-code overview of real-time driver tracking in ride-hailing apps if you want the product view.
Written by the team at Zafgo, a white-label ride-hailing platform. Drafted with AI assistance; code samples are simplified illustrations.
About the author
- Taxi companies and local operators kept telling us the same thing: big ride apps take a large share of every fare, and building your own app costs a fortune and takes months. Zafgo is our answer. We build ready rider, driver and courier apps plus a live dispatch console that operators publish under their own brand, from their own App Store and Google Play accounts, on their own server. They pay a setup fee and a flat monthly fee, and we take nothing from their rides. On DEV we share what we learn building it: dispatch, real-time tracking, maps costs and app store reviews.
Comments
Join the discussionNo comments yet. Be the first to comment.