Woosmap MultiSearch Android SDK

Explore available parameters and understand how to combine the different autocomplete services.

  1. Installation
  2. Implementing the MultiSearch Object

Installation

How to get a Git project into your build:

Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.WebGeoServices:multisearch-android:tag'
}

Implementing the MultiSearch Object

The library requires to set a key for each available API in your MultiSearch implementation, whether it’s a Woosmap API or for Google Places API.

Please refer to the documentation to get an API Key if necessary.

Additionally, for each provider configuration you can apply the same optional parameters as defined in the corresponding provider documentation.

When instantiating the Multisearch object, you need, at least, to specify your desired autocomplete services’ API keys and the order in which these services will be called:

Create MultiSearch object

MultiSearch multiSearch = new MultiSearch(getApplicationContext());

Then, create ProviderConfig objects by using ProviderConfig.Builder class and add provider to MultiSearch object.

ProviderConfig.Builder builder;

builder = new ProviderConfig.Builder(SearchProviderType.LOCALITIES)
        .key(<<woosmap_private_key>>);
multiSearch.addProvider(builder.build());//Add locality provider

builder = new ProviderConfig.Builder(SearchProviderType.STORE)
        .key(<<woosmap_private_key>>);
multiSearch.addProvider(builder.build());//Add Store provider

builder = new ProviderConfig.Builder(SearchProviderType.ADDRESS)
        .key(<<woosmap_private_key>>);
multiSearch.addProvider(builder.build());//Add Address provider

builder = new ProviderConfig.Builder(SearchProviderType.PLACES)
        .key(<<google_maps_api_key>>);
multiSearch.addProvider(builder.build());//Add Places provider

APIs will be called based on the order in which they were provided to MultiSearch object. In above code snippet following will be the order of the APIs:

LOCALITIESSTOREADDRESSPLACES

Specify debounceTime

Debounce time is the amount of time in miliseconds the autocomplete function will wait after the last received call before executing the next one. If no value is specified then autocomplete function will not wait for the next excecution call. You can specify debounce time by setting setDebounceTime property.

multiSearch.setDebounceTime(500);

Setting up callback listener

MultiSearch returns the autocomplete and details result using MultiSearchListener callback interface. This interface has two callback methods.

MultiSearchListener multiSearchListener = new MultiSearchListener() {
    @Override
    public void onSearchComplete(List<AutocompleteResponseItem> searchResult, WoosmapException exception) {
        if (exception==null){ //Check if no exception has occured during the autocomplete 
            Log.d("Multisearch","Result count is: " + searchResult.size());
        }
        else{
            Log.d("Multisearch","Exception is: " + exception.getMessage());
        }
    }

    @Override
    public void onDetailComplete(DetailsResponseItem detailResult, WoosmapException exception) {
        if (exception==null){ //Check if no exception has occured during the autocomplete 
            Log.d("Multisearch","Detail id is: " + detailResult.getId());
        }
        else{
            Log.d("Multisearch","Exception is: " + exception.getMessage());
        }
    }
};

multiSearch.addSearchListener(multiSearchListener);

Retrieve suggestions

You can retrieve suggestions from the user input by calling the autocompleteMulti method:

multiSearch.autocompleteMulti("paris");

Get Details

Finally, to get the suggestion details when a user selects one from the pick list, call the detailsMulti method. This method accepts two parameters.

multiSearch.detailsMulti(<<place_id>>,SearchProviderType.LOCALITIES);
Was this article helpful?
Have more questions? Submit a request