Snapping to roads
GET /v1/snap moves a point to the nearest point on the road network, and says which road that is: its class, its posted speed limit where the data has one, and whether it runs both ways. It is the step every route takes at each end, offered on its own.
curl -G "https://api.oslew.com/v1/snap" \
-H "Authorization: Bearer $GEO_API_KEY" \
--data-urlencode 'at=19.4326,-99.1332'from oslew import Client
# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")
answer = client.snap("19.4326,-99.1332")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.snap("19.4326,-99.1332");HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 295
ratelimit-reset: 1
{
"at": [
19.4326,
-99.1332
],
"snapped": {
"from": 355496,
"to": 355490,
"frac": 0.16199866758190418,
"lat": 19.43200133133587,
"lon": -99.13329035902773,
"distance_m": 67.23995201279342,
"time_ds": 110,
"len_m": 92,
"two_way": false
},
"class": "living_street",
"speed_limit_kmh": 30,
"provenance": {
"name": "overture-transportation",
"release": "2026-08-19.0",
"license": "ODbL-1.0"
},
"took_us": 320
}A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.
The Zócalo is a large square with no road through it, so the nearest place a car can be is 67 m away: aliving_street with a posted limit of 30 km/h, one-way, whose whole edge is 92 m long and takes 11 s to drive.
Parameters
| Parameter | Default | Is |
|---|---|---|
at | required | The point, lat,lon. |
profile | driving | Whose network to snap to: driving, walking, cycling or rail. A pedestrian's nearest way can be a footway a car cannot use; see routes and profiles. |
What comes back
| Field | Is |
|---|---|
snapped.lat, snapped.lon | The nearest point on a road — part-way along an edge, not at a junction. |
snapped.distance_m | Metres from at to it. |
snapped.from, snapped.to | The edge's two junctions, as node ids of this release's graph. Comparable between answers from one release; not stable across releases. |
snapped.frac | Where along the edge: 0 at from, 1 at to. frac × len_m is the metres from from. |
snapped.len_m | The whole edge's length, metres, measured along the road's shape. |
snapped.time_ds | The whole edge's travel time for the profile, in tenths of a second: 110 is 11 s. |
snapped.two_way | Whether the edge can also be travelled from to to from. false is a one-way street for this profile; on foot every way is two-way. |
class | The road's class in the profile's own list — primary, residential, living_street for driving; footway, steps, path on foot. |
speed_limit_kmh | The posted limit, below. null when the data gives none. |
provenance | The road data and its licence: Overture's transportation theme, ODbL-1.0. |
How far it looks
The search looks at the roads within about 600 m first and widens to about 9 km. Beyond that there is no nearest road to give, and the answer is still a 200: snapped, class andspeed_limit_kmh are all null. That differs from /v1/route, which cannot start without a road and refuses the same point with a 400.
Nearest means nearest and nothing else. The search does not know which way you are heading, which side of a divided road you are on, or what the street is called, so beside a junction or a dual carriageway the nearest edge can be the cross street or the carriageway going the other way. For one point that is usually what you want. For a sequence of points from a moving vehicle it is not — there, map matching uses the points before and after each one to pick the road it was really on.
Speed limits
speed_limit_kmh is the limit posted for general traffic on that edge, in the direction fromfrom to to, in whole km/h — limits recorded in miles an hour are converted. Limits for particular vehicles, such as buses, and limits that apply only at certain times are left out.
It is the road's limit whatever the profile, because "what is the limit on this road" is a question of its own — but ask with the default driving profile when that is the question, so that the road found is one a car can use.
What it is for
The limit where a vehicle is
One position, one question: what is the limit here? Snap it and read speed_limit_kmh, checkingdistance_m first — a position 40 m from the nearest road is probably in a car park, not on it. For a whole trip, match the trace instead and read speed_limits_kmh, which has the limit for every point on the road it was actually on; map matching shows how.
Moving a pin to the kerb
A geocoded address is often the middle of a building, and a driver needs the road in front of it. Snap the address and use the snapped position as the stop:
from oslew import Client
client = Client(base_url="https://api.oslew.com")
def kerbside(lat, lon, max_m=150):
"""The point on the road nearest an address, or None if the road is implausibly far."""
snap = client.snap(f"{lat},{lon}")["snapped"]
if snap is None or snap["distance_m"] > max_m:
return None # no road near: keep the address point and say so
return snap["lat"], snap["lon"]import { Client } from "@oslew/client";
const client = new Client({ baseUrl: "https://api.oslew.com" });
/** The point on the road nearest an address, or null if the road is implausibly far. */
async function kerbside(lat: number, lon: number, maxM = 150) {
const { snapped } = await client.snap(`${lat},${lon}`);
if (snapped === null || snapped.distance_m > maxM) return null; // no road near: keep the address point
return [snapped.lat, snapped.lon] as const;
}The nearest road is not always the one with the entrance on it — a corner building has two — so treat the result as a good default a person can correct, not as the address's access point.
Checking a point is near the network
snapped: null, or a distance_m of hundreds of metres, says a point is somewhere the network does not reach — a field, the sea, an area the loaded data does not cover. Checking before you route saves a 400 and lets you tell the user why.
You do not need to snap before routing: /v1/route snaps both ends itself, in the same way, and says where in snapped_from and snapped_to. For the nearest road alongside everything else at a point — the area, the time zone, the nearest places and stops — /v1/herecarries it in its road field.