Concepts / Building Search UI / Algolia Places
May. 10, 2019

Algolia Places

Using Places on Android

You can use Algolia Places on Android by instantiating a PlacesClient and using it for search:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 // Create an unauthenticated client:
PlacesClient places = new PlacesClient();
// or provide credentials to create an authenticated, full-fledged client:
PlacesClient places = new PlacesClient(applicationID, apiKey);

 // Create your query and set its parameters for your search
PlacesQuery query = new PlacesQuery();
query.setQuery("Paris").setType(PlacesQuery.Type.CITY).setHitsPerPage(10);
query.setAroundLatLngViaIP(false).setAroundLatLng(new PlacesQuery.LatLng(32.7767, -96.7970)); // Dallas, TX, USA
query.setLanguage("en").setCountries("fr", "us");

// Search Places
places.searchAsync(query, new AssertCompletionHandler() {
  @Override
  public void doRequestCompleted(JSONObject content, AlgoliaException error) {
        if (error != null) {
            handleError(error);
        } else {
            handleResults(content.optJSONArray("hits"););
        }
    }
});

Did you find this page helpful?