The Scenario
You are a fleet operations analyst. Last Tuesday a delivery van's GPS unit was behaving erratically — its tracking device had a loose antenna — and the system logged eighty position pings that are clearly off-road: scattered across fields, over buildings, through a parking structure. The raw data is in a Google Sheet, latitude in column A and longitude in column B. You need to snap those coordinates to the actual road network before the weekly fleet report goes to the operations director.
You have heard of map matching but have never called the Mapbox Map Matching API.
The bad version:
- Read the Mapbox Map Matching API documentation, learn that it accepts a GeoJSON LineString of coordinates in a specific format, has a hard limit of 100 waypoints per request, and requires timestamps or radiuses for each point if the trace is noisy.
- Write a script to batch the 80 pings into groups under 100, make the API calls, parse the snapped coordinate arrays out of the response, and reassemble them in the right row order.
- Realize that three pings are so far off-road that Mapbox cannot snap them and returns a gap in the trace — you have to decide how to handle that in the output.
The fleet report is due Friday morning. You have to fix the trace and compute total route distance from the snapped coordinates as well.
The Easy Way: One Prompt in SheetXAI
SheetXAI is an AI agent that lives inside your Google Sheet. It reads the raw GPS pings, sends them to the Mapbox Map Matching API in appropriately sized groups, and writes the corrected road-snapped coordinates back into the sheet — handling the batching and gap-flagging for you.
Take the GPS coordinates in columns A and B of this sheet, send them to the Mapbox map-matching API in groups of 100, and write the road-snapped latitude and longitude into columns C and D. Flag any pings that could not be snapped to a road in column E as UNSNAPPED.
What You Get
- Column C with road-snapped latitude for each ping, corrected to the nearest road geometry.
- Column D with road-snapped longitude.
- Column E blank for successfully matched pings; UNSNAPPED for any ping the API could not place on a road — typically because it is too far off-road for the matching radius.
What If the Data Is Not Quite Ready
The pings are timestamped and you want to preserve the timestamps in the output
Column C already has a timestamp for each ping. After snapping, you want the corrected coordinates alongside the original timestamps for the report.
Take GPS coordinates in columns A and B, preserving the timestamps in column C. Send the coordinates to the Mapbox map-matching API in groups of 100. Write snapped latitude into column D, snapped longitude into column E, and keep column C timestamps aligned. Flag unsnapped rows in column F as UNSNAPPED.
You want to compute total route distance from the snapped coordinates
After snapping, you need the cumulative route distance in kilometers for the full trace.
Snap all GPS coordinates in columns A and B to the road network using the Mapbox map-matching API. Write corrected coordinates into columns C and D. Then compute the cumulative distance in kilometers between consecutive snapped coordinate pairs and write the total route distance into cell E1.
About twenty of the eighty pings are clearly outliers — more than 500 meters from any road
You want to remove obvious outliers before sending to the map-matching API so they do not distort the trace.
First, flag any GPS coordinate in columns A and B that is more than 500 meters from the nearest road according to Mapbox as OUTLIER in column E. Then send the remaining coordinates to the Mapbox map-matching API in order and write the snapped coordinates into columns C and D.
Full pipeline: filter outliers, batch snap, compute segment distances, and flag large corrections
Remove any pings from columns A and B that are more than 300 meters from the nearest road — mark them as OUTLIER in column E. Send remaining coordinates to the Mapbox map-matching API in groups under 100. Write snapped coordinates into columns C and D. Compute the distance in meters between original and snapped coordinate for each ping and write into column F — flag any correction greater than 100 meters as LARGE CORRECTION in column G. Compute total route distance from snapped coordinates and write it into cell H1.
One prompt covers outlier filtering, batched map matching, correction distance computation, and total distance summary.
Try It
Get the 7-day free trial of SheetXAI and open your next GPS export — bring the raw lat/lon columns and ask SheetXAI to snap the trace to the road network through Mapbox. If you need to reverse-geocode the snapped coordinates into street addresses for a report, the reverse geocoding article covers that. The Mapbox hub lists every geographic workflow available.
