Skip to content
GuidesBlogPlaygroundDashboard

Snap a coordinate to the nearest road

client.routing.nearest(RoutingNearestParams { lat, lng, outputFields, 3 more } query, RequestOptionsoptions?): NearestResult { geometry, properties, type }
GET/api/v1/nearest

Snap a coordinate to the nearest road

ParametersExpand Collapse
query: RoutingNearestParams { lat, lng, outputFields, 3 more }
lat: number

Latitude

lng: number

Longitude

outputFields?: string

Comma-separated property fields to include

outputInclude?: string

Extra computed fields: bbox, distance, center

outputPrecision?: number

Coordinate decimal precision (1-15, default 7)

radius?: number

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
NearestResult { 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<number> | Array<Array<number>> | Array<Array<Array<number>>> | Array<Array<Array<Array<number>>>>

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

One of the following:
Array<number>
Array<Array<number>>
Array<Array<Array<number>>>
Array<Array<Array<Array<number>>>>
type: "Point" | "LineString" | "Polygon" | 3 more

Geometry type

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

Snap result metadata

distance_m?: number

Distance from the input coordinate to the snapped point in meters

edge_id?: number

ID of the road network edge that was snapped to

edge_length_m?: number

Length of the matched road edge in meters

highway?: string | null

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

osm_way_id?: number

OSM way ID of the matched road segment

surface?: string | null

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

type: "Feature"

Snap a coordinate to the nearest road

import Plaza from '@plazafyi/sdk';

const client = new Plaza({
  apiKey: process.env['PLAZA_API_KEY'], // This is the default and can be omitted
});

const nearestResult = await client.routing.nearest({ lat: 0, lng: 0 });

console.log(nearestResult.geometry);
{
  "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"
}