# Geocode an address, then route to it

Turn a typed address into coordinates, confirm the match, and pass it to the router without swapping anything.

Before you start, you need an [API key](../start/quickstart.md).

## Search for the place

Send free text in `q`. Use `near_text` when a name could match several places, because it ranks results near a landmark or district you name. If your app knows where the user is, follow [Search near your user](search-near-user.md) instead.

```bash
curl -s -H "X-API-Key: $QUADRUPER_KEY" \
  'https://quadruper.com/v2/geocode?q=SM%20City&near_text=Jaro%2C%20Iloilo%20City&limit=3'
```

## Check what came back

Read `results[0]` and confirm it's the place you meant. When you send `near_text`, `reference` shows the place that text resolved to. This is an example response:

```json schema=geocode-response
{
  "results": [{
    "source": "osm",
    "id": "node/123456",
    "name": "SM City Iloilo",
    "label": "SM City Iloilo, Mandurriao, Iloilo City",
    "location": [122.5517, 10.7139],
    "category": "shop",
    "type": "mall",
    "address": { "district": "Mandurriao", "city": "Iloilo City", "country_code": "ph" }
  }],
  "reference": { "label": "Jaro, Iloilo City", "location": [122.563, 10.727] },
  "attribution": [{ "source": "osm", "text": "© OpenStreetMap contributors", "license": "ODbL-1.0" }]
}
```

No match returns `200` with `"results": []`. If the `near_text` place can't be found, you get `422 reference_not_found`, so ask the user to rephrase it.

## Pass the location to the route

`location` is already `[lng, lat]`, the same order that `points` takes. Don't swap it.

```bash
curl -s -X POST -H 'Content-Type: application/json' -H "X-API-Key: $QUADRUPER_KEY" \
  -d '{"points":[[122.5621,10.7202],[122.5517,10.7139]],"steps":true}' \
  https://quadruper.com/v2/route
```

## Check your result

The response has one route, with a `steps` list on each leg. If a point has no road nearby, you get `422 point_not_snapped`, and `details.point_index` tells you which point it was. [`POST /v2/route`](../reference/route.md) documents every field.
