Skip to content
GuidesBlogPlaygroundDashboard

Snap a coordinate to the nearest road

client.Routing.Nearest(ctx, query) (*NearestResult, error)
GET/api/v1/nearest

Snap a coordinate to the nearest road

ParametersExpand Collapse
query RoutingNearestParams
Lat param.Field[float64]

Latitude

Lng param.Field[float64]

Longitude

OutputFields param.Field[string]optional

Comma-separated property fields to include

OutputInclude param.Field[string]optional

Extra computed fields: bbox, distance, center

OutputPrecision param.Field[int64]optional

Coordinate decimal precision (1-15, default 7)

Radius param.Field[int64]optional

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
type NearestResult struct{…}

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

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

Coordinates GeoJsonGeometryCoordinatesUnion

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

One of the following:
type GeoJsonGeometryCoordinatesPoint []float64

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

type GeoJsonGeometryCoordinatesLineStringOrMultiPoint [][]float64

Array of [lng, lat] positions

type GeoJsonGeometryCoordinatesPolygonOrMultiLineString [][][]float64

Array of linear rings / line strings

type GeoJsonGeometryCoordinatesMultiPolygon [][][][]float64

Array of polygons

Type GeoJsonGeometryType

Geometry type

One of the following:
const GeoJsonGeometryTypePoint GeoJsonGeometryType = "Point"
const GeoJsonGeometryTypeLineString GeoJsonGeometryType = "LineString"
const GeoJsonGeometryTypePolygon GeoJsonGeometryType = "Polygon"
const GeoJsonGeometryTypeMultiPoint GeoJsonGeometryType = "MultiPoint"
const GeoJsonGeometryTypeMultiLineString GeoJsonGeometryType = "MultiLineString"
const GeoJsonGeometryTypeMultiPolygon GeoJsonGeometryType = "MultiPolygon"
Properties NearestResultProperties

Snap result metadata

DistanceM float64optional

Distance from the input coordinate to the snapped point in meters

EdgeID int64optional

ID of the road network edge that was snapped to

EdgeLengthM float64optional

Length of the matched road edge in meters

Highway stringoptional

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

OsmWayID int64optional

OSM way ID of the matched road segment

Surface stringoptional

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

Type NearestResultType

Snap a coordinate to the nearest road

package main

import (
  "context"
  "fmt"

  "github.com/plazafyi/plaza-go"
  "github.com/plazafyi/plaza-go/option"
)

func main() {
  client := githubcomplazafyiplazago.NewClient(
    option.WithAPIKey("My API Key"),
  )
  nearestResult, err := client.Routing.Nearest(context.TODO(), githubcomplazafyiplazago.RoutingNearestParams{
    Lat: githubcomplazafyiplazago.F(0.000000),
    Lng: githubcomplazafyiplazago.F(0.000000),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", nearestResult.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"
}