Skip to content
GuidesBlogPlaygroundDashboard

Snap a coordinate to the nearest road

POST/api/v1/nearest

Snap a coordinate to the nearest road

Query ParametersExpand Collapse
lat: number

Latitude

lng: number

Longitude

"output[fields]": optional string

Comma-separated property fields to include

"output[include]": optional string

Extra computed fields: bbox, distance, center

"output[precision]": optional number

Coordinate decimal precision (1-15, default 7)

radius: optional number

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
NearestResult = object { geometry, properties, type }

GeoJSON Point Feature representing the nearest point on the road network to the input coordinate. Used for snapping GPS coordinates to roads.

geometry: GeoJsonGeometry { coordinates, type }

GeoJSON Geometry object per RFC 7946. Coordinates use [longitude, latitude] order. 3D coordinates [lng, lat, elevation] are used for elevation endpoints.

coordinates: array of number or array of array of number or array of array of array of number or array of array of array of array of number

Coordinates array. Nesting depth varies by geometry type: Point = [lng, lat], LineString = [[lng, lat], ...], Polygon = [[[lng, lat], ...], ...], etc.

One of the following:
Point = array of number

[longitude, latitude] or [longitude, latitude, elevation]

LineStringOrMultiPoint = array of array of number

Array of [lng, lat] positions

PolygonOrMultiLineString = array of array of array of number

Array of linear rings / line strings

MultiPolygon = array of array of array of array of number

Array of polygons

type: "Point" or "LineString" or "Polygon" or 3 more

Geometry type

One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
properties: object { distance_m, edge_id, edge_length_m, 3 more }

Snap result metadata

distance_m: optional number

Distance from the input coordinate to the snapped point in meters

edge_id: optional number

ID of the road network edge that was snapped to

edge_length_m: optional number

Length of the matched road edge in meters

highway: optional string

OSM highway tag value (e.g. residential, primary, motorway)

osm_way_id: optional number

OSM way ID of the matched road segment

surface: optional string

OSM surface tag value (e.g. asphalt, gravel, paved)

type: "Feature"

Snap a coordinate to the nearest road

curl https://plaza.fyi/api/v1/nearest \
    -X POST \
    -H "Authorization: Bearer $PLAZA_API_KEY"
{
  "geometry": {
    "coordinates": [
      2.3522,
      48.8566
    ],
    "type": "Point"
  },
  "properties": {
    "distance_m": 12.4,
    "edge_id": 0,
    "edge_length_m": 0,
    "highway": "highway",
    "osm_way_id": 0,
    "surface": "surface"
  },
  "type": "Feature"
}
Returns Examples
{
  "geometry": {
    "coordinates": [
      2.3522,
      48.8566
    ],
    "type": "Point"
  },
  "properties": {
    "distance_m": 12.4,
    "edge_id": 0,
    "edge_length_m": 0,
    "highway": "highway",
    "osm_way_id": 0,
    "surface": "surface"
  },
  "type": "Feature"
}