Nearest API

Snaps a coordinate to the street network and returns the nearest n matches.

Request

Request Format

https://us1.locationiq.com/v1/nearest/driving/{coordinates}?key=<YOUR_ACCESS_TOKEN>&number={number}

Request Example

Querying nearest two snapped locations of -0.142001,51.501284 with a bearing between 20° - 340°.

https://us1.locationiq.com/v1/nearest/driving/-0.142001,51.501284?key=<YOUR_ACCESS_TOKEN>&number=2&bearings=0,20

Where coordinates only supports a single {longitude},{latitude} entry.

In addition to the general options the following options are supported for this service:

OptionValuesDescription
numberinteger >= 1 (default 1)Number of nearest segments that should be returned.

Response

Response Example

{
    "waypoints": [{
            "nodes": [
                5393917730,
                5393917729
            ],
            "hint": "inUjk411IxMPAAAAAAAAACEAAABbAQAAlUZNQAAAAAD1D9xAA1aRQggAAAAAAAAAEAAAALAAAAAIFwEA3dX9_7zVEQNP1f3_5NgRAwIA3wB42O4j",
            "distance": 90.435751,
            "location": [
                -0.141859,
                51.500476
            ],
            "name": "Ambassador's Court"
        },
        {
            "nodes": [
                5393917731,
                5393917730
            ],
            "hint": "inUjk411IxMRAAAAAAAAABAAAABqAQAAHdpdQAAAAADMRVpAOMCXQggAAAAAAAAACAAAALgAAAAIFwEA0tX9_6DVEQNP1f3_5NgRAwEALxZ42O4j",
            "distance": 93.4557,
            "location": [
                -0.14187,
                51.500448
            ],
            "name": "Ambassador's Court"
        }
    ],
    "code": "Ok"
}

Response Parameters

  • code if the request was successful Ok otherwise see the service dependent and general status codes.
  • waypoints array of Waypoint objects sorted by distance to the input coordinate. Each object has at least the following additional properties:
    • nodes: Array of OpenStreetMap node ids.