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

# Reverse geocoding

> Turn a tapped coordinate into an address in React Native.

[Reverse Search](/services/reverse) takes a latitude/longitude pair and returns the nearest
named place. The usual pattern is a long-press on the map — "what is here?".

## The request

```javascript theme={null}
import { baatoRequest } from "./baato";

export async function reverseGeocode(latitude, longitude) {
  const data = await baatoRequest("/reverse", {
    lat: latitude,
    lon: longitude,
  });

  return data[0];
}
```

<ParamField query="lat" type="number" required>
  Latitude of the point to look up.
</ParamField>

<ParamField query="lon" type="number" required>
  Longitude of the point to look up.
</ParamField>

<ParamField query="radius" type="number">
  Search radius in kilometres. Widen it for rural areas where features are sparse.
</ParamField>

<ParamField query="limit" type="integer">
  Maximum number of results to return.
</ParamField>

## Wiring it to a long-press

```javascript theme={null}
import MapLibreGL from "@maplibre/maplibre-react-native";

function PickerMap() {
  const [place, setPlace] = useState(null);

  const handleLongPress = async (event) => {
    // MapLibre hands you [lon, lat] — Baato wants them named and separate
    const [lon, lat] = event.geometry.coordinates;

    try {
      const result = await reverseGeocode(lat, lon);
      setPlace(result);
    } catch (error) {
      console.warn("Reverse geocoding failed", error);
    }
  };

  return (
    <MapLibreGL.MapView style={{ flex: 1 }} onLongPress={handleLongPress}>
      {place && (
        <MapLibreGL.PointAnnotation
          id="picked"
          coordinate={[place.centroid.lon, place.centroid.lat]}
        />
      )}
    </MapLibreGL.MapView>
  );
}
```

<Warning>
  Note the destructuring above: `event.geometry.coordinates` is `[lon, lat]`, but
  `reverseGeocode` takes `(latitude, longitude)`. Getting this backwards returns a plausible
  address for entirely the wrong place rather than an error. See
  [coordinate order](/about/concepts#coordinate-order).
</Warning>

## Handling empty results

Reverse search returns an empty `data` array when nothing is near enough — over water, or
in an unmapped area. Handle it explicitly instead of reading `data[0]` blindly:

```javascript theme={null}
const data = await baatoRequest("/reverse", { lat, lon });

if (data.length === 0) {
  setPlace(null);
  setMessage("No address found here");
  return;
}
```

## Next

<Columns cols={2}>
  <Card title="Directions" icon="route" href="/examples/react-native/directions">
    Route between the points you have picked.
  </Card>

  <Card title="Reverse Search API" icon="code" href="/services/reverse">
    Full parameter reference and playground.
  </Card>
</Columns>
