Skip to content
GuidesBlogPlaygroundDashboard

Snap a coordinate to the nearest road

routing.nearest_post(RoutingNearestPostParams**kwargs) -> NearestResult
POST/api/v1/nearest

Snap a coordinate to the nearest road

ParametersExpand Collapse
lat: float

Latitude

lng: float

Longitude

output_fields: Optional[str]

Comma-separated property fields to include

output_include: Optional[str]

Extra computed fields: bbox, distance, center

output_precision: Optional[int]

Coordinate decimal precision (1-15, default 7)

radius: Optional[int]

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
class NearestResult:

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

geometry: GeoJsonGeometry

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

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

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

One of the following:
List[float]

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

List[List[float]]

Array of [lng, lat] positions

List[List[List[float]]]

Array of linear rings / line strings

List[List[List[List[float]]]]

Array of polygons

type: Literal["Point", "LineString", "Polygon", 3 more]

Geometry type

One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
properties: Properties

Snap result metadata

distance_m: Optional[float]

Distance from the input coordinate to the snapped point in meters

edge_id: Optional[int]

ID of the road network edge that was snapped to

edge_length_m: Optional[float]

Length of the matched road edge in meters

highway: Optional[str]

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

osm_way_id: Optional[int]

OSM way ID of the matched road segment

surface: Optional[str]

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

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_post(
    lat=0,
    lng=0,
)
print(nearest_result.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"
}