> ## Documentation Index
> Fetch the complete documentation index at: https://docs.justrouting.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Nearest

> Snap a coordinate to the road network and get the nearest routable segments.

## Overview

Nearest API snaps a single coordinate to the road network and returns the nearest `n` segments. Useful for validating whether a coordinate is routable, getting the exact snapped position, and obtaining `hint` values that speed up subsequent requests.

Powered by the OSRM Nearest service.

## Endpoint

```
GET https://api.justrouting.tech/nearest/v1/{profile}/{coordinates}
```

| URL parameter | Description |
| - | - |
| `profile` | `driving` or `motorcycle` |
| `coordinates` | A **single** `{lng},{lat}` pair |

## Request Parameters

### Service options

| Parameter | Type | Default | Description |
| - | - | - | - |
| `number` | int | `1` | Number of nearest segments to return |

### General options

These options apply to all routing services. Options that take one value per coordinate use the array-like encoding `{option}={element};{element}[;...]` — the number of elements must match the number of coordinates (except `generate_hints` and `exclude`). Pass an empty element to use the default for that coordinate, e.g. `bearings=;90,20;`.

| Parameter | Type | Default | Description |
| - | - | - | - |
| `bearings` | string | — | Limit snapping to segments with the given bearing; each element is `{value},{range}` with value 0–360° clockwise from true north and range 0–180° |
| `radiuses` | string | — | Limit snapping to the given radius in meters per coordinate, `unlimited` for no limit |
| `generate_hints` | bool | `true` | Add a `hint` to each response waypoint for reuse in later requests via `hints` |
| `hints` | string | — | Base64 `hint` from a previous response; speeds up snapping significantly |
| `approaches` | string | — | Restrict the road direction at a waypoint; per element `curb` / `opposite` / `unrestricted` (default) |
| `exclude` | string | — | Additive list of road classes to avoid, e.g. `exclude=motorway` |
| `snapping` | string | `default` | `any` snaps to any edge in the graph; `default` avoids edges that cannot be used as start/end points |
| `skip_waypoints` | bool | `false` | Remove waypoints from the response (they are still calculated, just not serialized) |

<Info>
  Nearest returns only `waypoints` — with `skip_waypoints=true` the response contains just the `code` field. Technically possible, but not useful.
</Info>

## Quickstart

```bash theme={null}
curl "https://api.justrouting.tech/nearest/v1/driving/103.708362,1.357371?number=2" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Response

```json response-example.json theme={null}
{
  "code": "Ok",
  "waypoints": [
    {
      "name": "Bayfront Avenue",
      "location": [103.708799, 1.357033],
      "distance": 4.15,
      "hint": "KSoKADRYroqUBAEAEAAAABkAAAAGAAAAAAAAABhnCQCLtwAA_0vMAKlYIQM8TMwArVghAwEAAQH1a66g",
      "nodes": [2264199819, 0]
    },
    {
      "name": "Temasek Boulevard",
      "location": [103.709782, 1.357132],
      "distance": 11.81,
      "hint": "KSoKADRYroqUBAEABgAAAAAAAAAAAAAAKQAAABhnCQCLtwAA7kvMAAxZIQM8TMwArVghAwAAAQH1a66g",
      "nodes": [0, 2045820592]
    }
  ]
}
```

### Response fields

| Field | Description |
| - | - |
| `waypoints[]` | Snap results, sorted by distance |
| `waypoints[].location` | The exact snapped position `[lng, lat]` |
| `waypoints[].distance` | Offset from the input coordinate to the snapped point, in **meters** |
| `waypoints[].hint` | Opaque segment identifier — pass it back via the `hints` parameter of route/table to speed up snapping |
| `waypoints[].nodes` | Pair of OSM node ids |

## Typical uses

* **Coordinate cleanup**: validate with `nearest` first — a large `distance` means the coordinate is far from any road
* **Speed up hot paths**: cache the `hint` and reuse it in subsequent `route`/`table` requests

## Related

* [Directions API](/api-reference/directions)
* [Errors](/errors)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.