# Nearby

Find the nearest places with one or more OpenStreetMap tags, such as schools, banks or bus stops.

`GET /v2/nearby`. Auth: API key.

This call needs a key. There is no keyless trial for it.

## Naming what to find

Name the places you want in one of two ways. A call uses one or the other. Sending both, or neither, is `400 invalid_request`.

- `category`, with an optional `type`. `category` is an OpenStreetMap key such as `amenity`. `type` is one value of that key, or a comma-separated list of values, such as `school,hospital`. Each value becomes its own tag (`amenity:school`, `amenity:hospital`). Without `type`, the tag is the bare key, and any value of that key matches.
- `tags`, a comma-separated list where each tag is `key:value` or a bare `key`, such as `amenity:hospital,shop:supermarket,highway:bus_stop`.

A call takes 1 to 12 tags. A tag that appears twice is `400 invalid_request`.

## Parameters

| Parameter | Required | Description |
|---|---|---|
| `point` | Yes | `lng,lat` |
| `category` | With `type`, or instead of `tags` | An OSM key matching `^[a-z][a-z0-9_]{0,39}$`, such as `amenity`. |
| `type` | No | Only with `category`. One OSM value or a comma-separated list, each matching `^[a-z0-9_]{1,40}$`. |
| `tags` | Instead of `category` | Comma-separated `key` or `key:value`, using the same patterns. |
| `limit` | No | 1 to 20. The most results per tag. See below. |
| `lang` | No | Two-letter code such as `en` |

Any other parameter, or a value outside these rules, is `400 invalid_request`.

### Limit

`limit` counts per tag, not for the whole call. With `tags=amenity:restaurant,amenity:hospital&limit=3`, you get up to 3 restaurants and up to 3 hospitals. A common kind of place cannot push a rare kind off the list.

Without `limit`, each tag gets 10, or `floor(60 / number of tags)` when that is smaller. So one tag gets 10 and 12 tags get 5 each. A call returns at most 60 results, so a `limit` that makes the number of tags times `limit` more than 60 is `400 invalid_request`.

## Examples

```bash
# One kind of place
curl -s -H "X-API-Key: $QUADRUPER_KEY" \
  'https://quadruper.com/v2/nearby?point=122.5517,10.7139&category=amenity&type=school&limit=3'

# Schools and hospitals, with a type list
curl -s -H "X-API-Key: $QUADRUPER_KEY" \
  'https://quadruper.com/v2/nearby?point=122.5517,10.7139&category=amenity&type=school,hospital&limit=5'

# Several kinds in one call
curl -s -H "X-API-Key: $QUADRUPER_KEY" \
  'https://quadruper.com/v2/nearby?point=122.5517,10.7139&tags=amenity:hospital,shop:supermarket,highway:bus_stop&limit=3'
```

The first call returns the three nearest schools:

```json schema=nearby-response
{
  "results": [
    {
      "source": "osm",
      "id": "way/456599639",
      "name": "Iloilo Scholastic Academy",
      "label": "Iloilo Scholastic Academy, Explorer Road, Mandurriao, Iloilo City",
      "location": [122.5479636,10.7132268],
      "category": "amenity",
      "type": "school",
      "address": { "street": "Explorer Road", "locality": "Mandurriao", "district": "Mandurriao", "city": "Iloilo City", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 415
    },
    {
      "source": "osm",
      "id": "way/476539834",
      "name": "Bolilao Elementary School",
      "label": "Bolilao Elementary School, Mandurriao, Iloilo City, Iloilo",
      "location": [122.5545015,10.710892],
      "category": "amenity",
      "type": "school",
      "address": { "locality": "Bolilao", "district": "Mandurriao", "city": "Iloilo City", "state": "Iloilo", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 453
    },
    {
      "source": "osm",
      "id": "way/676419001",
      "name": "Bakhaw Integrated School",
      "label": "Bakhaw Integrated School, Kawayanan Street, Mandurriao, Iloilo City, Iloilo",
      "location": [122.5543613,10.7183077],
      "category": "amenity",
      "type": "school",
      "address": { "street": "Kawayanan Street", "locality": "Buhang Taft-North", "district": "Mandurriao", "city": "Iloilo City", "state": "Iloilo", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 570
    }
  ],
  "attribution": [{ "source": "osm", "text": "© OpenStreetMap contributors", "license": "ODbL-1.0" }]
}
```

The third call returns up to 3 places for each of the 3 tags, merged into one list, nearest first:

Results follow how OpenStreetMap tags places as mapped. The first hospital below, for example, is a pet hospital that OSM tags as `amenity=hospital`.

```json schema=nearby-response
{
  "results": [
    {
      "source": "osm",
      "id": "node/14094996934",
      "name": "SM City Iloilo",
      "label": "SM City Iloilo, Iloilo City Bike Lane, Mandurriao, Iloilo City",
      "location": [122.5521274,10.7136643],
      "category": "highway",
      "type": "bus_stop",
      "address": { "street": "Iloilo City Bike Lane", "locality": "Bolilao", "district": "Mandurriao", "city": "Iloilo City", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 54
    },
    {
      "source": "osm",
      "id": "node/12178150985",
      "name": "SM Supermarket",
      "label": "SM Supermarket, Benigno S. Aquino, Jr. Avenue, Mandurriao, Iloilo City",
      "location": [122.5507714,10.7143451],
      "category": "shop",
      "type": "supermarket",
      "address": { "street": "Benigno S. Aquino, Jr. Avenue", "locality": "Bolilao", "district": "Mandurriao", "city": "Iloilo City", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 113
    },
    {
      "source": "osm",
      "id": "node/13174731353",
      "name": "Aquino - Jalandoni",
      "label": "Aquino - Jalandoni, Jalandoni Street, Jaro, Iloilo City",
      "location": [122.5530068,10.7140732],
      "category": "highway",
      "type": "bus_stop",
      "address": { "street": "Jalandoni Street", "locality": "Bolilao", "district": "Jaro", "city": "Iloilo City", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 144
    },
    {
      "source": "osm",
      "id": "node/6010561888",
      "name": "Save More",
      "label": "Save More, Benigno S. Aquino, Jr. Avenue, Mandurriao, Iloilo City",
      "location": [122.5528458,10.713081],
      "category": "shop",
      "type": "supermarket",
      "address": { "street": "Benigno S. Aquino, Jr. Avenue", "locality": "Bolilao", "district": "Mandurriao", "city": "Iloilo City", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 155
    },
    {
      "source": "osm",
      "id": "node/8666518395",
      "name": "Smallville",
      "label": "Smallville, Benigno S. Aquino Jr. Avenue, Mandurriao, Iloilo City",
      "location": [122.5520316,10.7120744],
      "category": "highway",
      "type": "bus_stop",
      "address": { "street": "Benigno S. Aquino Jr. Avenue", "locality": "Bolilao", "district": "Mandurriao", "city": "Iloilo City", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 206
    },
    {
      "source": "osm",
      "id": "node/12584512007",
      "name": "Plazuela Dos Market Bazaar",
      "label": "Plazuela Dos Market Bazaar, Pison Avenue, Mandurriao, Iloilo City",
      "location": [122.5497108,10.7115113],
      "category": "shop",
      "type": "supermarket",
      "address": { "street": "Pison Avenue", "locality": "Atria Park District", "district": "Mandurriao", "city": "Iloilo City", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 343
    },
    {
      "source": "osm",
      "id": "way/786338266",
      "name": "Cornerstone Pet Hospital",
      "label": "Cornerstone Pet Hospital, 69 Jalandoni Street, Jaro, Ilolo",
      "location": [122.5594477,10.7174673],
      "category": "amenity",
      "type": "hospital",
      "address": { "house_number": "69", "street": "Jalandoni Street", "locality": "Bakhaw", "district": "Jaro", "city": "Ilolo", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 935
    },
    {
      "source": "osm",
      "id": "way/324713282",
      "name": "QualiMed Hospital",
      "label": "QualiMed Hospital, Donato Pison Avenue, Mandurriao, Iloilo",
      "location": [122.5478301,10.7062846],
      "category": "amenity",
      "type": "hospital",
      "address": { "street": "Donato Pison Avenue", "locality": "Tabucan", "district": "Mandurriao", "city": "Iloilo", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 946
    },
    {
      "source": "osm",
      "id": "relation/15805976",
      "name": "Iloilo Mission Hospital",
      "label": "Iloilo Mission Hospital, Mission Road, Jaro, Iloilo City",
      "location": [122.5603406,10.7145276],
      "category": "amenity",
      "type": "hospital",
      "address": { "street": "Mission Road", "locality": "Jereos", "district": "Jaro", "city": "Iloilo City", "postcode": "5000", "country": "Philippines", "country_code": "ph" },
      "distance_m": 947
    }
  ],
  "attribution": [{ "source": "osm", "text": "© OpenStreetMap contributors", "license": "ODbL-1.0" }]
}
```

## Response fields

Each result has the same fields as a [`/v2/geocode`](geocode.md) result, plus `distance_m`. Every result keeps its own `category` and `type`, so group them yourself when you want a list per kind.

| Field | Description |
|---|---|
| `results[].distance_m` | The straight-line distance from `point`, in whole metres. |

- Matches come from within 5 km of `point`. Nothing farther is returned.
- Results are sorted nearest first, whatever the order the geocoder used.
- A place that matches two of your tags, such as `amenity` and `amenity:school`, appears once.
- Fewer matches than `limit`, or none, is still `200`. No match is `"results": []`, not 404.

## Finding tag names

A tag is an OpenStreetMap key and value. Some common ones:

| Tag | Finds |
|---|---|
| `amenity:school` | Schools |
| `amenity:hospital` | Hospitals |
| `amenity:bank` | Banks |
| `amenity:marketplace` | Public markets |
| `shop:supermarket` | Supermarkets |
| `highway:bus_stop` | Bus stops |
| `leisure:park` | Parks |

The [OpenStreetMap wiki's Map features page](https://wiki.openstreetmap.org/wiki/Map_features) lists the rest.

## Errors

| Status | Code | When |
|---|---|---|
| 400 | `invalid_request` | Both or neither of `category` and `tags`, `type` without `category`, a bad tag, a repeated tag, more than 12 tags, a bad `limit`, or a number of tags times `limit` over 60. |
| 501 | `capability_unavailable` | The geocoder behind the API can't search nearby. Read `capabilities.nearby` in [`GET /v2/info`](info.md): when it is missing, this call isn't available. |
| 401 | `unauthorized` | No valid API key. |
| 429 | `rate_limited`, `data_cap_exceeded` | Over a rate limit or your monthly data cap. See [Errors](errors.md). |

If one of the lookups behind a multi-tag call fails, the whole call fails with that error. You never get a partial list.

## Attribution

The response has an `attribution` list, as on [`/v2/reverse`](reverse.md). It lists Overture Maps too whenever a result comes from it. See [Show attribution](../guides/attribution.md).
