APIs
Map matching API
A map matching API takes a noisy GPS trace and works out which roads the vehicle actually drove. oslew uses a hidden Markov model in the Newson–Krumm style: every fix is weighed against the fixes either side of it, so one stray position does not drag the route onto a side street. A trace of up to 10,000 points comes back with each point’s position on its road, the road class and posted limit, the distance along the matched roads and a confidence.
Last reviewed
GPS positions are estimates. A receiver in a street of tall buildings sees reflected signals and lands on the next block; one that loses the sky in a tunnel returns nothing, then something far away; one sitting in a car park drifts a few metres at every fix. Drawn raw, a trace wanders off the road, jumps between parallel streets and invents kilometres. Map matching recovers the path the vehicle took on the network, and POST /v1/match does it for a whole trace in one request.
How the matcher decides
For each fix, the matcher collects up to five candidate positions: the nearest points on roads within search_m of it. Two probabilities then compete. A candidate is likelier the closer it lies to the observed fix, on a bell curve whose width is sigma_m, the typical error of your receivers. A step from one fix’s candidate to the next fix’s candidate is likelier the closer the road route between them is in length to the straight line the trace drew — a car does not go round the block between two fixes a few seconds apart. The single most likely sequence of candidates over the whole trace wins.
That is why one noisy fix beside a side street does not pull the route into it: the fixes around it vote against the detour. It is also why the first fix of a trace is the least certain one, with nothing before it to weigh against.
The chain breaks, and the trace is matched in separate segments, wherever a fix has no road within search_m (it comes back null), wherever consecutive fixes are too far apart to be one continuous drive — a recording gap, a tunnel, a ferry — and wherever no route on the network can make the step between two fixes. The segments are joined in the answer, but the distance leaves out the breaks.
The request
A JSON body, sent with Content-Type: application/json, holding points — a list of lat, lon and an optional time — and four settings: search_m, sigma_m, profile (driving by default; a fleet of bicycles matches onto cycling) and geometry. A trace carries at most 10,000 points, and the body at most 2 MiB, which a full trace with timestamps fits well inside. The time field is accepted and ignored by the match; keep it in your own copy of the trace, because you will need it for speeds.
Tuning is mostly sigma_m. Set too tight, every small error looks improbable and the match chases the noise onto side streets. search_m must cover the worst error you expect; set too narrow, fixes go unmatched and the trace splits into pieces.
The answer
| Field | What it holds |
|---|---|
points |
One per input fix: the matched position, the road segment’s two junctions and how far along it, and metres from the observed fix — or null |
speed_limits_kmh |
One per input fix: the posted limit on its matched road, or null |
classes |
One per input fix: the matched road’s class, such as primary or residential |
distance_m |
Metres along the matched roads, within segments |
duration_s |
Seconds along them at the roads’ own speeds — not how long the trace took |
confidence |
The share of all fixes matched within twice sigma_m of where they were observed |
matched, unmatched |
Counts of fixes that found a road and fixes that did not |
geometry |
The matched route as [lat, lon] pairs, segments joined end to end |
The three per-point lists line up with your input, index for index, which makes the answer easy to join back to your own records, timestamps included. confidence depends on sigma_m, so compare it only between traces matched with the same settings, and use it to rank traces for review rather than as a probability. The geometry runs junction to junction and joins segments with a straight line, so split it at nulls before drawing a trace with a gap.
One point, no trace: snapping
GET /v1/snap?at=lat,lon moves a single position to the nearest point on a road and says which road that is: its class, its posted limit where the data has one, whether it runs both ways and how far the position was from it. The search starts close and widens; if nothing is found even then, the answer is still a 200 with the road fields null. Snapping considers distance alone, which is right for one isolated fix — a tracker that woke, reported once and slept — and wrong for a moving vehicle, where the fixes around each point are the best evidence of the road.
Snapping also answers questions that have nothing to do with traces: moving a geocoded pin from the middle of a building to the kerb a driver can stop at, or checking that a point is near the network at all before routing from it.
Posted limits, and the roads without one
speed_limits_kmh and a snap’s speed_limit_kmh carry the limit posted for general traffic on the matched road segment. Limits for particular vehicles, and limits that apply only at certain times, are left out. How many roads carry a posted limit depends on the source data for the area, and minor streets often carry none, so expect nulls on residential mileage. Where the limit is null, nothing was posted in the data. The router’s default speed for a road class is an estimate for timing routes, and it is not substituted, because nobody posted it. Speeds of your own, computed from matched positions and your timestamps, belong beside the limit — the fleet GPS cleanup workflow works that through, including what to report when the limit is unknown.
Traces are not logged
A trace is a record of where a person drove, and it is handled as one: it travels in the request body, and the query log never records a body. A snap is a GET, so its position is subject to the query log’s rules instead: Positions are kept only as the level-12 cell they fall in, about 2 km across. The security page sets out everything the log keeps. As with every oslew route, the key belongs on your server and never in a browser or a device.
What it costs, and the licence
A match is one request against the routing rate however many fixes it carries, so a full-length trace costs the same as a single fix; on the Routing plan that rate is 5 requests a second sustained, burst 25. Matched positions, classes and limits derive from road data licensed ODbL-1.0. Showing them publicly — a matched route drawn for a customer — calls for attribution; a database of matched traces that you share with others is share-alike, as the licensing page explains.
Limits, stated plainly
- At most 10,000 points per request; longer traces are split and overlapped.
- Timestamps are not used by the match, and nothing in the answer is a speed the vehicle drove.
- Durations are at the roads’ free-flow speeds, never on a traffic feed.
- Posted limits exist for only part of the network, and conditional limits are omitted.
- Matching needs road data loaded where the vehicle drove; elsewhere every fix is null.
Bottom line
Send whole traces to /v1/match and single fixes to /v1/snap. Tune sigma_m to your devices, keep your own timestamps for speeds, treat a null limit as unknown rather than guessing one, and see the routing API when you need to plan a drive rather than reconstruct one.
Questions
What is the difference between map matching and snapping?
Snapping moves one point to the nearest road and considers nothing else, so beside a junction or a dual carriageway it can choose the wrong road. Map matching looks at the whole sequence and picks the road each fix was most plausibly on, given the fixes before and after it. Snap a single position; match a trace.
Do the points need timestamps?
You may send them, and you should keep them, but the matcher does not use them: the match depends on the order of the points alone. Durations in the answer come from the roads’ speeds, not from your clock, so any speed you compare against a limit comes from your timestamps and the matched positions.
Why is the speed limit null for so many points?
Because no limit is posted for that road in the source data. How many roads carry one depends on the data for the area, and minor streets often have none. The speed routing assumes for a road class is an estimate for timing routes, not a legal limit, and it is deliberately not returned in its place.
Are our GPS traces stored or logged?
Request bodies are not logged: not the Wi-Fi and cell ids a device saw, not a map-matching trace, not a batch file’s rows. The query log records that a request was made, to which route, with its status and latency; the trace itself, being the body of the request, is never written to it.
How should I set sigma_m and search_m for phone GPS?
Set sigma_m to the typical error of your devices and search_m wide enough to cover the worst error you expect; a phone in a dense city is noisier than a vehicle tracker under open sky. If many points come back unmatched, widen search_m. If the matched route zigzags through parallel streets, raise sigma_m.
What if a trace is longer than one request allows?
Split it into pieces of at most 10,000 points that overlap by a few points, so that the first points of each piece have predecessors to be weighed against, and keep the overlapping points’ answers from the earlier piece. Each piece is one request against the routing rate, whatever its length.