Skip to content
GuidesPlaygroundDashboard

Snap a coordinate to the nearest road

NearestResult Routing.Nearest(RoutingNearestParamsparameters, CancellationTokencancellationToken = default)
GET/api/v1/nearest

Snap a coordinate to the nearest road

ParametersExpand Collapse
RoutingNearestParams parameters
required Double lat

Latitude

required Double lng

Longitude

Long radius

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
class NearestResult:

GeoJSON Point Feature snapped to the nearest road segment

required GeoJsonGeometry Geometry
required Coordinates Coordinates

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
IReadOnlyList<Double>
IReadOnlyList<IReadOnlyList<Double>>
IReadOnlyList<IReadOnlyList<IReadOnlyList<Double>>>
IReadOnlyList<IReadOnlyList<IReadOnlyList<IReadOnlyList<Double>>>>
required Type Type
One of the following:
"Point"Point
"LineString"LineString
"Polygon"Polygon
"MultiPoint"MultiPoint
"MultiLineString"MultiLineString
"MultiPolygon"MultiPolygon
required Properties Properties
Double DistanceM

Distance to nearest road in meters

Long? EdgeID

Road edge ID

required Type Type

Snap a coordinate to the nearest road

RoutingNearestParams parameters = new()
{
    Lat = 0,
    Lng = 0,
};

var nearestResult = await client.Routing.Nearest(parameters);

Console.WriteLine(nearestResult);
{
  "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"
}