Cleaning Fleet GPS Traces with Mapbox Map Matching API
Learn how to smooth noisy GPS traces from fleet vehicles using Mapbox’s Map Matching API, with a concrete request example and practical verification steps.
26 Sept 2025, 20:02 UTC

Problem: Jittery GPS traces distort fleet analytics
Raw location streams from smartphones or telematics devices often contain spikes, dropped points, and drift caused by satellite visibility or urban canyons. When these traces are fed directly into distance, speed, or route‑efficiency calculations, the noise inflates metrics and masks real‑world driving patterns.
How the Map Matching API works
The Map Matching API takes an ordered list of latitude/longitude pairs (with optional timestamps) and snaps each point to the nearest navigable segment in Mapbox’s street network. It returns a GeoJSON FeatureCollection that represents the most likely vehicle path, along with per‑segment confidence scores and, if requested, turn‑by‑turn steps. The service is stateless; each request is independent, so there is no server‑side state to roll back.
Worked example: matching a 5‑minute trace
Suppose you have collected the following six points from a test vehicle (longitude, latitude) and want to obtain a smoothed line:
curl -X POST \
"https://api.mapbox.com/matching/v5/mapbox.mapbox-streets-v8/
-73.985428,40.748817,-73.985123,40.748910,-73.984800,40.749005,
-73.984500,40.749100,-73.984200,40.749180,-73.983900,40.749250" \
?geometries=geojson&steps=true&access_token=YOUR_MAPBOX_TOKEN
The API responds with a FeatureCollection similar to the following (truncated for brevity):
{
"type":"FeatureCollection",
"features":[{
"type":"Feature",
"properties":{"confidence":0.92,"distance":215.4,"duration":18.7},
"geometry":{"type":"LineString",
"coordinates":[[-73.9854,40.7488],[-73.9851,40.7489],[-73.9848,40.7490]]}
}]
}
You can add the returned LineString to a Mapbox GL JS map as a line layer and visually compare it to the original raw points; the matched line should follow the underlying road network rather than jumping across blocks.
Trade‑offs and limits
- Pricing: The service charges per matched point after the free tier of 50 000 points/month. Unexpected spikes in trace volume can lead to surprise costs, so monitor usage via the Mapbox billing dashboard and set alerts.
- Coverage gaps: In regions where Mapbox’s street dataset is sparse (e.g., newly developed areas or remote rural roads), the API may fail to find a close match, resulting in low confidence or dropped points. Supplementing with local OpenStreetMap data or increasing GPS sampling frequency can mitigate this.
- Complex interchanges: Multi‑level junctions or abrupt direction changes can confuse the matching algorithm, especially when timestamps are sparse. Providing higher‑frequency GPS updates (e.g., one point per second) and enabling the
steps=trueoption improves reliability.
Actionable next steps
- Instrument your fleet‑tracking pipeline to batch GPS points (e.g., every 30 seconds) and POST them to the matching endpoint.
- Parse the response, extract the
confidencefield, and flag any segment below 0.8 for further review or additional sampling. - Render the matched GeoJSON in Mapbox GL JS using a line layer with a distinct colour; overlay the raw points as circles to visually verify the improvement.
- Set up a usage alert in your Mapbox account that triggers when monthly matched‑point consumption reaches 80 % of the free quota, allowing you to adjust sampling or budget before overage charges occur.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.