Skip to content
GuidesBlogPlaygroundDashboard

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

string outputFields

Comma-separated property fields to include

string outputInclude

Extra computed fields: bbox, distance, center

Long outputPrecision

Coordinate decimal precision (1-15, default 7)

Long radius

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
class NearestResult:

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

required GeoJsonGeometry Geometry

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

required Coordinates Coordinates

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

One of the following:
IReadOnlyList<Double>
IReadOnlyList<IReadOnlyList<Double>>
IReadOnlyList<IReadOnlyList<IReadOnlyList<Double>>>
IReadOnlyList<IReadOnlyList<IReadOnlyList<IReadOnlyList<Double>>>>
required Type Type

Geometry type

One of the following:
"Point"Point
"LineString"LineString
"Polygon"Polygon
"MultiPoint"MultiPoint
"MultiLineString"MultiLineString
"MultiPolygon"MultiPolygon
required Properties Properties

Snap result metadata

Double DistanceM

Distance from the input coordinate to the snapped point in meters

Long EdgeID

ID of the road network edge that was snapped to

Double EdgeLengthM

Length of the matched road edge in meters

string? Highway

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

Long OsmWayID

OSM way ID of the matched road segment

string? Surface

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

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