Skip to content
GuidesBlogPlaygroundDashboard

Snap a coordinate to the nearest road

routing.nearest(**kwargs) -> NearestResult { geometry, properties, type }
GET/api/v1/nearest

Snap a coordinate to the nearest road

ParametersExpand Collapse
lat: Float

Latitude

lng: Float

Longitude

output_fields: String

Comma-separated property fields to include

output_include: String

Extra computed fields: bbox, distance, center

output_precision: Integer

Coordinate decimal precision (1-15, default 7)

radius: Integer

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
class 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[Float] | Array[Array[Float]] | Array[Array[Array[Float]]] | Array[Array[Array[Array[Float]]]]

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

One of the following:
Array[Float]

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

Array[Array[Float]]

Array of [lng, lat] positions

Array[Array[Array[Float]]]

Array of linear rings / line strings

Array[Array[Array[Array[Float]]]]

Array of polygons

type: :Point | :LineString | :Polygon | 3 more

Geometry type

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

Snap result metadata

distance_m: Float

Distance from the input coordinate to the snapped point in meters

edge_id: Integer

ID of the road network edge that was snapped to

edge_length_m: Float

Length of the matched road edge in meters

highway: String

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

osm_way_id: Integer

OSM way ID of the matched road segment

surface: String

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

type: :Feature

Snap a coordinate to the nearest road

require "plaza"

plaza = Plaza::Client.new(
  api_key: "My API Key",
  environment: "local" # defaults to "production"
)

nearest_result = plaza.routing.nearest(lat: 0, lng: 0)

puts(nearest_result)
{
  "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"
}