Skip to content
GuidesPlaygroundDashboard

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

Radius param.Field[int64]optional

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
type NearestResult struct{…}

GeoJSON Point Feature snapped to the nearest road segment

Coordinates GeoJsonGeometryCoordinatesUnion

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
type GeoJsonGeometryCoordinatesArray []float64
type GeoJsonGeometryCoordinatesArray [][]float64
type GeoJsonGeometryCoordinatesArray [][][]float64
type GeoJsonGeometryCoordinatesArray [][][][]float64
Type GeoJsonGeometryType
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
DistanceM float64optional

Distance to nearest road in meters

EdgeID int64optional

Road edge ID

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