> ## 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.

# Java

> Integrate the Baato API into Android projects with the official Java client.

The Java client wraps the Baato API in listener-based request builders that fit Android's
threading model — every call is asynchronous, with `onSuccess` and `onFailed` callbacks.

<Columns cols={2}>
  <Card title="Source on GitHub" icon="github" href="https://github.com/baato/java-client" horizontal>
    `baato/java-client`
  </Card>

  <Card title="Runnable examples" icon="android" href="/examples/android-java/autocomplete" horizontal>
    Autocomplete, drop-a-pin, map styles and navigation.
  </Card>
</Columns>

## Installation

The client is distributed through [JitPack](https://jitpack.io). Add the repository to your
project's `build.gradle`:

```groovy theme={null}
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
```

Then add the dependency to your application's `build.gradle`:

```groovy theme={null}
dependencies {
   implementation 'com.github.baato:java-client:${latest-version}'
}
```

<Note>
  Replace `${latest-version}` with the current release tag from the
  [GitHub releases page](https://github.com/baato/java-client/releases).
</Note>

## Usage

<AccordionGroup>
  <Accordion title="Search — place suggestions" icon="magnifying-glass" defaultOpen>
    ```java theme={null}
    new BaatoSearch(this)
        .setApiVersion("1")  // default
        .setAccessToken("YOUR_BAATO_ACCESS_TOKEN")
        .setQuery(query)
        .setLimit(5) //optional parameter
        .withListener(new BaatoSearch.BaatoSearchRequestListener() {
            @Override
            public void onSuccess(SearchAPIResponse places) {
                // get the list of search results here
                Log.d(TAG, "onSuccess:search " + places.toString());
            }

            @Override
            public void onFailed(Throwable error) {
                // get the error messages here
                Log.d(TAG, "onFailed:search " + error.getMessage());
            }
        })
        .doRequest();
    ```

    Search results carry no coordinates — pass a result's `placeId` to `BaatoPlace` to get
    them. See [the two-step search flow](/about/concepts#identifying-a-place).
  </Accordion>

  <Accordion title="Reverse Search — coordinates to an address" icon="location-crosshairs">
    ```java theme={null}
    new BaatoReverse(this)
        .setApiVersion("1")  // default
        .setAccessToken("YOUR_BAATO_ACCESS_TOKEN")
        .setLatLon(new LatLon(lat, lon))
        .setLimit(5) //optional parameter
        .withListener(new BaatoReverse.BaatoReverseRequestListener() {
            @Override
            public void onSuccess(PlaceAPIResponse places) {
                // success response here
                Log.d(TAG, "onSuccess: reverse " + places.toString());
            }

            @Override
            public void onFailed(Throwable error) {
                // failure response here
                Log.d(TAG, "onFailed:reverse " + error.getMessage());
            }
        })
        .doRequest();
    ```
  </Accordion>

  <Accordion title="Places — full detail for a place ID" icon="location-dot">
    ```java theme={null}
    new BaatoPlace(this)
        .setApiVersion("1")  // default
        .setAccessToken("YOUR_BAATO_ACCESS_TOKEN")
        .setPlaceId("112020")
        .withListener(new BaatoPlace.BaatoPlaceRequestListener() {
            @Override
            public void onSuccess(PlaceAPIResponse place) {
                // success response here
                Log.d(TAG, "onSuccess: reverse " + place.toString());
            }

            @Override
            public void onFailed(Throwable error) {
                // failure response here
                Log.d(TAG, "onFailed:reverse " + error.getMessage());
            }
        })
        .doRequest();
    ```
  </Accordion>

  <Accordion title="Directions — routes between points" icon="route">
    ```java theme={null}
    String points[] = new String[]{"27.73405,85.33685", "27.7177,85.3278"};

    new BaatoRouting(this)
            .setPoints(points)
            .setAccessToken("YOUR_BAATO_ACCESS_TOKEN")
            .setMode(mode) //eg bike, car, foot
            .setAlternatives(false) //optional parameter
            .setInstructions(true) //optional parameter
            .withListener(new BaatoRouting.BaatoRoutingRequestListener() {
                @Override
                public void onSuccess(DirectionsAPIResponse directionResponse) {
                    // success response here
                    Log.d(TAG, "onSuccess: routes" + directionResponse.toString());
                }
                @Override
                public void onFailed(Throwable error) {
                    // failure response here
                    Log.d(TAG, "onFailed:routes " + error.getMessage());
                }
            })
            .doRequest();
    ```

    <Warning>
      Waypoints are `"lat,lon"` strings, the reverse of the `[lng, lat]` order map renderers
      use. See [coordinate order](/about/concepts#coordinate-order).
    </Warning>
  </Accordion>
</AccordionGroup>

## Next

<Columns cols={2}>
  <Card title="Autocomplete" icon="magnifying-glass" href="/examples/android-java/autocomplete">
    A working search screen built on this client.
  </Card>

  <Card title="Navigation SDK" icon="diamond-turn-right" href="/libraries/navigation-sdk">
    Add turn-by-turn navigation on top.
  </Card>
</Columns>
