Skip to content
GuidesPlaygroundDashboard

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

radius: Integer

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
class NearestResult { geometry, properties, type }

GeoJSON Point Feature snapped to the nearest road segment

geometry: GeoJsonGeometry { coordinates, type }
coordinates: Array[Float] | Array[Array[Float]] | Array[Array[Array[Float]]] | Array[Array[Array[Array[Float]]]]

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
Array[Float]
Array[Array[Float]]
Array[Array[Array[Float]]]
Array[Array[Array[Array[Float]]]]
type: :Point | :LineString | :Polygon | 3 more
One of the following:
:Point
:LineString
:Polygon
:MultiPoint
:MultiLineString
:MultiPolygon
properties: { distance_m, edge_id}
distance_m: Float

Distance to nearest road in meters

edge_id: Integer

Road edge ID

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": [
      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"
}