# Addresses from coordinates (reverse geocoding)

> Turn a GPS coordinate into a readable address, search places by text for a map search box, and combine both with road distance.

Source: https://www.wayline.cloud/docs/guides/geocoding

Your app has a `lat,lng` (from a phone's GPS or a pin dropped on a map) and needs to show a place name. Or a user types an address and you need the coordinate. Wayline does both with OpenStreetMap data.

## Coordinate to address

```bash
curl "https://api.wayline.cloud/v1/reverse-geocode?point=23.7461,90.3742" \
  -H "Authorization: Bearer $WAYLINE_KEY"
```

```json
{
  "results": [
    {
      "name": "Satmasjid Road",
      "formatted_address": "Satmasjid Road, Dhanmondi, Dhaka 1209, Bangladesh",
      "location": { "lat": 23.7461, "lng": 90.3742 },
      "type": "street",
      "category": "highway:primary",
      "address": { "street": "Satmasjid Road", "district": "Dhanmondi", "city": "Dhaka", "postcode": "1209", "country": "Bangladesh", "country_code": "BD" },
      "distance_meters": 12,
      "osm": { "type": "way", "id": 123456, "key": "highway", "value": "primary" }
    }
  ],
  "units_charged": 1,
  "region": "bd"
}
```

- `admin_areas` gives the administrative areas containing the point (in Bangladesh: division, district, upazila and union; a level is `null` where it isn't mapped).
- `types=street,locality,district,city` skips shops and other points of interest.
- `limit` (1–5) returns more nearby candidates, closest first.
- `radius_meters` (up to 5,000) ignores anything farther away. Without it, a search that finds nothing within about 1 km widens to 5 km once (sparse rural areas).
- `lang=bn` returns Bengali names where OpenStreetMap has them.
- Many points at once (a day of check-ins): `POST /v1/reverse-geocode/batch` with up to 100 points. See [Field sales and rural visits](/docs/guides/field-sales).

## Text search (map search box)

```bash
curl "https://api.wayline.cloud/v1/geocode?q=Square%20Hospital&near=23.75,90.38&limit=5" \
  -H "Authorization: Bearer $WAYLINE_KEY"
```

`near` (the user's location or the map center) ranks closer results first and selects the region. Results are limited to that region. For autocomplete, debounce keystrokes (about 250 ms) and send the partial text. Responses are cached, so repeated prefixes are fast.

## Pin on a map, then distance

A typical "set pickup and drop-off" flow:

1. The user drops a pin or picks a search result. You now have `lat,lng`.
2. Call `/v1/reverse-geocode` to show the address under the pin.
3. Call `/v1/distance` with both coordinates (and `profile=motorcycle` for riders) to get road distance and drive time.

## Accuracy in practice

Address detail depends on how well an area is mapped in OpenStreetMap. In dense cities you usually get the street and area. In rural areas you often get the village, union or upazila rather than a house number, and `admin_areas` still tells you the district and upazila. Results always include `distance_meters`, so you can tell an exact match from a nearby landmark. Data is refreshed from OpenStreetMap regularly.

Map data © [OpenStreetMap contributors](https://www.openstreetmap.org/copyright).
