Skip to content
GuidesPlaygroundDashboard

Snap a coordinate to the nearest road

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

Snap a coordinate to the nearest road

ParametersExpand Collapse
query: RoutingNearestParams { lat, lng, radius }
lat: number

Latitude

lng: number

Longitude

radius?: number

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
NearestResult { geometry, properties, type }

GeoJSON Point Feature snapped to the nearest road segment

geometry: GeoJsonGeometry { coordinates, type }
coordinates: Array<number> | Array<Array<number>> | Array<Array<Array<number>>> | Array<Array<Array<Array<number>>>>

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array<number>
Array<Array<number>>
Array<Array<Array<number>>>
Array<Array<Array<Array<number>>>>
type: "Point" | "LineString" | "Polygon" | 3 more
One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
properties: Properties { distance_m, edge_id }
distance_m?: number

Distance to nearest road in meters

edge_id?: number | null

Road edge ID

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": [
      0
    ],
    "type": "Point"
  },
  "properties": {
    "distance_m": 0,
    "edge_id": 0
  },
  "type": "Feature"
}
Returns Examples
{
  "geometry": {
    "coordinates": [
      0
    ],
    "type": "Point"
  },
  "properties": {
    "distance_m": 0,
    "edge_id": 0
  },
  "type": "Feature"
}