## Snap a coordinate to the nearest road `client.Routing.NearestPost(ctx, body) (*NearestResult, error)` **post** `/api/v1/nearest` Snap a coordinate to the nearest road ### Parameters - `body RoutingNearestPostParams` - `Lat param.Field[float64]` Latitude - `Lng param.Field[float64]` Longitude - `OutputFields param.Field[string]` Comma-separated property fields to include - `OutputInclude param.Field[string]` Extra computed fields: bbox, distance, center - `OutputPrecision param.Field[int64]` Coordinate decimal precision (1-15, default 7) - `Radius param.Field[int64]` Search radius in meters (default 500, max 5000) ### Returns - `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. - `Geometry GeoJsonGeometry` 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. - `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 - `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 float64` Distance from the input coordinate to the snapped point in meters - `EdgeID int64` ID of the road network edge that was snapped to - `EdgeLengthM float64` Length of the matched road edge in meters - `Highway string` OSM highway tag value (e.g. `residential`, `primary`, `motorway`) - `OsmWayID int64` OSM way ID of the matched road segment - `Surface string` OSM surface tag value (e.g. `asphalt`, `gravel`, `paved`) - `Type NearestResultType` - `const NearestResultTypeFeature NearestResultType = "Feature"` ### Example ```go 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.NearestPost(context.TODO(), githubcomplazafyiplazago.RoutingNearestPostParams{ Lat: githubcomplazafyiplazago.F(0.000000), Lng: githubcomplazafyiplazago.F(0.000000), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", nearestResult.Geometry) } ``` #### Response ```json { "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" } ```