oslew docs
Console
Menu

Map matching

POST /v1/match takes a GPS trace — a list of positions in the order they were recorded — and answers the roads it most likely followed: for every point, where on which road it really was, and for the trace, the route, its length and time, the posted limit and class under every point, and how well it all fitted. It uses the hidden Markov model of Newson and Krumm, which weighs each point against the ones either side of it rather than snapping each on its own.

curl
curl -X POST "https://api.oslew.com/v1/match" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"points":[{"lat":19.419276,"lon":-99.179338,"time":1790175600},{"lat":19.418751,"lon":-99.179701,"time":1790175605},{"lat":19.41867,"lon":-99.179614,"time":1790175610},{"lat":19.418502,"lon":-99.179014,"time":1790175615},{"lat":19.418286,"lon":-99.178608,"time":1790175620},{"lat":19.417033,"lon":-99.179268,"time":1790175625},{"lat":19.416802,"lon":-99.179338,"time":1790175630},{"lat":19.416776,"lon":-99.178855,"time":1790175635},{"lat":19.416914,"lon":-99.178812,"time":1790175640},{"lat":19.418012,"lon":-99.178069,"time":1790175645},{"lat":19.418268,"lon":-99.178079,"time":1790175650},{"lat":19.418769,"lon":-99.177802,"time":1790175655},{"lat":19.419165,"lon":-99.177555,"time":1790175660},{"lat":19.419798,"lon":-99.177323,"time":1790175665},{"lat":19.419971,"lon":-99.177179,"time":1790175670},{"lat":19.420875,"lon":-99.177583,"time":1790175675},{"lat":19.421131,"lon":-99.177514,"time":1790175680},{"lat":19.42292,"lon":-99.177679,"time":1790175685},{"lat":19.423246,"lon":-99.176215,"time":1790175690},{"lat":19.42322,"lon":-99.175986,"time":1790175695},{"lat":19.423306,"lon":-99.175722,"time":1790175700},{"lat":19.423814,"lon":-99.174224,"time":1790175705},{"lat":19.424459,"lon":-99.172921,"time":1790175710},{"lat":19.424828,"lon":-99.172014,"time":1790175715},{"lat":19.425023,"lon":-99.171867,"time":1790175720}],"geometry":false}'
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

answer = client.match(
    {
    "points": [
        {"lat": 19.419276, "lon": -99.179338, "time": 1790175600},
        {"lat": 19.418751, "lon": -99.179701, "time": 1790175605},
        {"lat": 19.41867, "lon": -99.179614, "time": 1790175610},
        {"lat": 19.418502, "lon": -99.179014, "time": 1790175615},
        {"lat": 19.418286, "lon": -99.178608, "time": 1790175620},
        {"lat": 19.417033, "lon": -99.179268, "time": 1790175625},
        {"lat": 19.416802, "lon": -99.179338, "time": 1790175630},
        {"lat": 19.416776, "lon": -99.178855, "time": 1790175635},
        {"lat": 19.416914, "lon": -99.178812, "time": 1790175640},
        {"lat": 19.418012, "lon": -99.178069, "time": 1790175645},
        {"lat": 19.418268, "lon": -99.178079, "time": 1790175650},
        {"lat": 19.418769, "lon": -99.177802, "time": 1790175655},
        {"lat": 19.419165, "lon": -99.177555, "time": 1790175660},
        {"lat": 19.419798, "lon": -99.177323, "time": 1790175665},
        {"lat": 19.419971, "lon": -99.177179, "time": 1790175670},
        {"lat": 19.420875, "lon": -99.177583, "time": 1790175675},
        {"lat": 19.421131, "lon": -99.177514, "time": 1790175680},
        {"lat": 19.42292, "lon": -99.177679, "time": 1790175685},
        {"lat": 19.423246, "lon": -99.176215, "time": 1790175690},
        {"lat": 19.42322, "lon": -99.175986, "time": 1790175695},
        {"lat": 19.423306, "lon": -99.175722, "time": 1790175700},
        {"lat": 19.423814, "lon": -99.174224, "time": 1790175705},
        {"lat": 19.424459, "lon": -99.172921, "time": 1790175710},
        {"lat": 19.424828, "lon": -99.172014, "time": 1790175715},
        {"lat": 19.425023, "lon": -99.171867, "time": 1790175720},
    ],
    "geometry": False,
},
)
TypeScript
import { Client } from "@oslew/client";

// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });

const answer = await client.match({
  points: [
    { lat: 19.419276, lon: -99.179338, time: 1790175600 },
    { lat: 19.418751, lon: -99.179701, time: 1790175605 },
    { lat: 19.41867, lon: -99.179614, time: 1790175610 },
    { lat: 19.418502, lon: -99.179014, time: 1790175615 },
    { lat: 19.418286, lon: -99.178608, time: 1790175620 },
    { lat: 19.417033, lon: -99.179268, time: 1790175625 },
    { lat: 19.416802, lon: -99.179338, time: 1790175630 },
    { lat: 19.416776, lon: -99.178855, time: 1790175635 },
    { lat: 19.416914, lon: -99.178812, time: 1790175640 },
    { lat: 19.418012, lon: -99.178069, time: 1790175645 },
    { lat: 19.418268, lon: -99.178079, time: 1790175650 },
    { lat: 19.418769, lon: -99.177802, time: 1790175655 },
    { lat: 19.419165, lon: -99.177555, time: 1790175660 },
    { lat: 19.419798, lon: -99.177323, time: 1790175665 },
    { lat: 19.419971, lon: -99.177179, time: 1790175670 },
    { lat: 19.420875, lon: -99.177583, time: 1790175675 },
    { lat: 19.421131, lon: -99.177514, time: 1790175680 },
    { lat: 19.42292, lon: -99.177679, time: 1790175685 },
    { lat: 19.423246, lon: -99.176215, time: 1790175690 },
    { lat: 19.42322, lon: -99.175986, time: 1790175695 },
    { lat: 19.423306, lon: -99.175722, time: 1790175700 },
    { lat: 19.423814, lon: -99.174224, time: 1790175705 },
    { lat: 19.424459, lon: -99.172921, time: 1790175710 },
    { lat: 19.424828, lon: -99.172014, time: 1790175715 },
    { lat: 19.425023, lon: -99.171867, time: 1790175720 },
  ],
  geometry: false,
});
Response
HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 294
ratelimit-reset: 1

{
  "points": [
    {
      "lat": 19.419265833691888,
      "lon": -99.1793149055659,
      "from": 362390,
      "to": 362686,
      "along": 0.16342062635322144,
      "distance_m": 2.6727302657997343
    },
    {
      "lat": 19.418717279588495,
      "lon": -99.1795863931191,
      "from": 362686,
      "to": 362687,
      "along": 0,
      "distance_m": 12.590083383713226
    },
    {
      "lat": 19.418717279588495,
      "lon": -99.1795863931191,
      "from": 362686,
      "to": 362687,
      "along": 0,
      "distance_m": 6.001708302961281
    },
    {
      "lat": 19.418447264747087,
      "lon": -99.17902412186542,
      "from": 362688,
      "to": 361352,
      "along": 0,
      "distance_m": 6.1781608772235606
    },
    {
      "lat": 19.41828749262708,
      "lon": -99.17860207985096,
      "from": 361352,
      "to": 362389,
      "along": 0.045549726075291,
      "distance_m": 0.6426478129502552
    }
  ],
  "speed_limits_kmh": [
    50,
    null,
    null,
    null,
    null
  ],
  "classes": [
    "primary",
    "residential",
    "residential",
    "residential",
    "residential"
  ],
  "geometry": [],
  "distance_m": 1835,
  "duration_s": 154.9,
  "confidence": 0.8,
  "matched": 25,
  "unmatched": 0,
  "provenance": {
    "name": "overture-transportation",
    "release": "2026-08-19.0",
    "license": "ODbL-1.0"
  },
  "took_us": 3881
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call. Shortened for the page: points shows 5 of 25. Shortened for the page: speed_limits_kmh shows 5 of 25. Shortened for the page: classes shows 5 of 25.

Twenty-five points five seconds apart, two minutes of driving; the page shows the first five of each list. All 25 matched, along 1,835 m of road that takes 154.9 s at the release's speeds. The first point is on aprimary road posted at 50 km/h and the next four on residential streets with no posted limit. The second point was 12.6 m from its road, more than twice the GPS noise the request assumed; points like it are whyconfidence is 0.8 and not 1 — 20 of the 25 landed within twice that noise.

The request

A JSON body, sent with Content-Type: application/json:

FieldDefaultIs
pointsrequiredThe trace, in order: {"lat", "lon", "time"?}, 1 to 10,000 of them.
search_m50How far from a point a road may be and still be a candidate, metres. Clamped to 5–200.
sigma_m4.07The GPS noise: the typical error of a position, metres. Clamped to 1–50.
profiledrivingWhose network to match onto: driving, walking, cycling or rail.
geometrytrueWhether to return the matched route's path.

time is accepted and not used: the match depends on the order of the points, not their timestamps. Keep it in your own copy of the trace; you will want it for speeds. Durations in the answer come from the road's speeds, not from the clock.

Fewer than one point or more than 10,000 is a 400, between 1 and 10000 points, and a latitude or longitude off the globe is a 400 naming it. A body without its content type is refused with a plain-text 415, and one with a field of the wrong type with 422 — seeerrors. A body can be at most 2 MB; 10,000 points with timestamps are well under half that.

How a trace is matched

  1. Every point gets up to five candidates: the nearest roads within search_m, each a position on that road.
  2. A candidate is likelier the closer it is to the point, on a normal curve whose width is sigma_m.
  3. A step from one point's candidate to the next point's is likelier the closer the route between them is in length to the straight line between the two points — a car does not go round the block between two fixes five seconds apart.
  4. The single most likely sequence of candidates, over the whole trace, is chosen.

The chain of points breaks, and the trace is matched in segments, wherever:

  • a point has no road within search_m — it comes back null;
  • two consecutive points are more than 2 km apart — a gap in recording, a tunnel, a flight;
  • no route on the network can make the step between two points.

Each segment is matched on its own, and the answer joins them. A segment's first point has nothing before it to weigh against, so it is the least certain point of its segment: a first fix on a junction is as much on the cross street as on the road the trace then follows.

Choosing sigma_m and search_m

sigma_m should be the typical error of the device. The default, 4.07 m, is Newson and Krumm's measured value for a vehicle's GPS receiver. search_m has to cover the worst error you expect, because a point whose true road is farther away than that cannot be matched to it. Starting points:

Sourcesigma_msearch_m
A vehicle tracker or telematics unit with a clear sky4–5 (the default)50 (the default)
A phone in a vehicle or a pocket, in a cityabout 10100
A phone among tall buildings, or a coarse tracker15–20150–200

Too small a sigma_m and every point's small error looks unlikely, so the match chases the noise onto side streets. Too small a search_m and points go unmatched, splitting the trace. Too large asearch_m costs time and offers more wrong candidates, though never more than five a point. Ifunmatched is high, raise search_m; if the route zigzags through parallel streets, raisesigma_m.

The answer

FieldIs
pointsOne per input point, in order: {lat, lon, from, to, along, distance_m} — the matched position on the road, the edge's two junctions, how far along it (0 at from, 1 at to), and metres from the observed point — or null where no road was within search_m.
speed_limits_kmhOne per input point: the posted limit on its matched edge, or null where none is posted or the point is unmatched.
classesOne per input point: the matched road's class, primary, residential and so on.
geometryThe matched route as [lat, lon] pairs: each matched position and the junctions between them. Empty when you ask for geometry: false.
distance_mMetres along the matched route, from the first matched point to the last, within segments.
duration_sSeconds along it at the release's speeds — posted limit, else class speed — not live traffic, and not how long the trace took.
confidence0 to 1: the share of all the points that were matched within twice sigma_m of where they were observed.
matched, unmatchedHow many points were matched, and how many were not.

The three lists line up with your input: index i of points, speed_limits_kmhand classes are all about your point i. That is what makes the answer easy to join back to your own data, timestamps included.

geometry joins the segments end to end with nothing to mark the join, so a trace with a gap draws a straight line across it. Where it matters, split the drawing yourself at the null points and at jumps of more than 2 km. Like a route's, the path runs junction to junction, so a curve between two junctions is drawn straight; distance_m is measured along the real road.

What it is for

Mileage

Summing the straight lines between raw GPS points overstates distance: a parked phone drifting a few metres every fix adds up to kilometres by morning, and every wobble on a straight road adds a little. distance_m is the length of the road the trace was on. It does not include the gaps between segments; if a trace has one, decide whether to add the straight-line distance across it or to report the gap.

Speeding

The limit is in speed_limits_kmh; the speed comes from your timestamps. Measure between matched positions rather than raw ones, so the noise does not register as speed:

Python
import math
from oslew import Client

client = Client(base_url="https://api.oslew.com")

def metres(a, b):
    """Great-circle distance between two {lat, lon} points."""
    p1, p2 = math.radians(a["lat"]), math.radians(b["lat"])
    dp, dl = p2 - p1, math.radians(b["lon"] - a["lon"])
    h = math.sin(dp / 2) ** 2 + math.cos(p1) * math.cos(p2) * math.sin(dl / 2) ** 2
    return 2 * 6_371_000 * math.asin(math.sqrt(h))

answer = client.match({"points": trace, "sigma_m": 10, "search_m": 100, "geometry": False})
matched, limits = answer["points"], answer["speed_limits_kmh"]

for i in range(1, len(trace)):
    a, b, limit = matched[i - 1], matched[i], limits[i]
    seconds = trace[i]["time"] - trace[i - 1]["time"]
    if a is None or b is None or limit is None or seconds <= 0:
        continue
    kmh = metres(a, b) / seconds * 3.6   # a straight line is never longer than the road
    if kmh > limit * 1.1:
        print(f"point {i}: {kmh:.0f} km/h where {limit} is posted")

The straight line between two matched positions is never longer than the road between them, so the speed it gives errs low: what it flags, happened. Where the limit is null, nothing is posted in the data; do not substitute the class speed, which is an estimate for routing and not a limit.

Cleaning a trace

Replace each point with its matched position, keep its timestamp, and drop the nulls: the result sits on the road, and the jitter is gone. Cleaning GPS traces works this through on a whole file.

Longer traces

Split a trace of more than 10,000 points into pieces, and overlap them by a few points so that the first points of each piece have predecessors to be weighed against; keep the overlapping points' answers from the earlier piece. Each piece is one request and one token from the routing bucket, whatever its length.

Python
def match_long(trace, piece=10_000, overlap=20, **options):
    """Match a trace of any length; points[i] lines up with trace[i]."""
    points = []
    start = 0
    while start < len(trace):
        chunk = trace[start:start + piece]
        answer = client.match({"points": chunk, "geometry": False, **options})
        keep = answer["points"] if start == 0 else answer["points"][overlap:]
        points.extend(keep)
        if start + piece >= len(trace):
            break
        start += piece - overlap
    return points
TypeScript
async function matchLong(trace: { lat: number; lon: number; time?: number }[], piece = 10_000, overlap = 20) {
  const points = [];
  for (let start = 0; start < trace.length; start += piece - overlap) {
    const chunk = trace.slice(start, start + piece);
    const answer = await client.match({ points: chunk, geometry: false });
    points.push(...(start === 0 ? answer.points : answer.points.slice(overlap)));
    if (start + piece >= trace.length) break;
  }
  return points; // points[i] lines up with trace[i]
}

Endpoints

POST/v1/matchrouting

Match a GPS trace onto the roads (Newson–Krumm HMM): per point the edge and position it most likely lies on, the matched route, its length and duration, and a confidence.