Skip to content
GuidesPlaygroundDashboard

Snap a coordinate to the nearest road

routing.nearest(RoutingNearestParams**kwargs) -> NearestResult
GET/api/v1/nearest

Snap a coordinate to the nearest road

ParametersExpand Collapse
lat: float

Latitude

lng: float

Longitude

radius: Optional[int]

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
class NearestResult:

GeoJSON Point Feature snapped to the nearest road segment

geometry: GeoJsonGeometry
coordinates: Union[List[float], List[List[float]], List[List[List[float]]], List[List[List[List[float]]]]]

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
List[float]
List[List[float]]
List[List[List[float]]]
List[List[List[List[float]]]]
type: Literal["Point", "LineString", "Polygon", 3 more]
One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
properties: Properties
distance_m: Optional[float]

Distance to nearest road in meters

edge_id: Optional[int]

Road edge ID

type: Literal["Feature"]

Snap a coordinate to the nearest road

import os
from plaza import Plaza

client = Plaza(
    api_key=os.environ.get("PLAZA_API_KEY"),  # This is the default and can be omitted
)
nearest_result = client.routing.nearest(
    lat=0,
    lng=0,
)
print(nearest_result.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"
}