Sorry, you need to enable JavaScript to visit this website.

Documentation

Documentation

Initialization

There are two ways to perform a search:

  1. Create an SearchAPI (android-sdk-search) object

  2. Start and bind to a SearchService (android-sdk-search-extensions)

You should use the first option if you want to handle multithreading / orientation changing and caching by yourself.
The second option is dedicated to you if you want to have an easy, out of the box Android Service which will handle most of the mentioned problems by itself.
Both options are described below. They all use the same public API.
In both cases, you will need the appropriate Search API key. For more information on obtaining and configuring TomTom API keys and their configuration, go to the "Getting started" subpage.

A SearchApi object is created in the following manner:

_

SearchApi searchApi = OnlineSearchApi.create(context);
private val searchApi = OnlineSearchApi.create(context)!!

 

The alternative to using an SearchAPI object is to create the
SearchService. To do so, at first use SearchServiceManager to create
ServiceConnection object and set SearchServiceConnectionCallback to
react on bind to the service event:

_

searchServiceConnection = SearchServiceManager.createAndBind(getContext(),
        searchServiceConnectionCallback());
val searchServiceConnection = SearchServiceManager.createAndBind(context,
    searchServiceConnectionCallback)

 

To unbind from SearchService use the following:

_

SearchServiceManager.unbind(getContext(), searchServiceConnection);
SearchServiceManager.unbind(context, searchServiceConnection)

 

In the above example, the SearchFragmentPresenter was chosen to play a
role of the listener on a such callback. An example implementation can
be as follows:

_

@Override
public void onBindSearchService(SearchService service) {
    searchService = service;
}
override fun onBindSearchService(service: SearchService) {
    val searchService = service
}

 

The Android Search API provides simple yet very handy functionality of
searching. Application developer can implement his own search component
using either a classic callback-based approach or use a reactive search.

First approach involves using the void search() method, taking
SearchQuery and FuzzySearchResultListener implementation as parameters.
Implementation of FuzzySearchResultListener should cover the following two methods:

void onSearchResult(FuzzySearchResponse results);

 

void onSearchError(final SearchError error);

 

The methods are calling back a list of SearchResult objects with corresponding
content. All poles of SearchResult have associated getters, so its
information is easily accessible.

Another way to subscribe a search response is to use a reactive search
method. It returns a RxJavas Observable<List<SearchResult>>. To take
advantage of this implementation, one has to subscribe for it (for
instance with a Disposable<List<SearchResult>> or a
Consumer<List<SearchResult>>.

Example implementation can look like the below code:

_

searchService.search(query)
        .subscribeOn(getWorkingScheduler())
        .observeOn(getResultScheduler())
        .subscribe(observer);
searchService.search(query)
    .subscribeOn(workingScheduler)
    .observeOn(resultScheduler)
    .subscribe(observer)

 

Example implementation of subscriber:

_

    new DisposableSingleObserver<FuzzySearchResponse>() {
@Override
public void onSuccess(FuzzySearchResponse fuzzySearchResponse) {
    lastSearchResult = fuzzySearchResponse.getResults();
    searchView.updateSearchResults(fuzzySearchResponse.getResults());
    searchFinished();
}

@Override
public void onError(Throwable throwable) {
    searchView.showSearchFailedMessage(throwable.getMessage());
    searchView.updateSearchResults(ImmutableList.of());
    searchFinished();
}
val observer = object : DisposableSingleObserver<FuzzySearchResponse>() {
    override fun onSuccess(fuzzySearchResponse: FuzzySearchResponse) {
        Resource.success(fuzzySearchResponse.results)
    }

    override fun onError(throwable: Throwable) {
        Resource.error(null, Error(throwable.message))
    }
}

 

Please note, a consecutive search request cannot be made before its
successor’s callback (either onSearchResult or onSearchError) is
received.

Concurrent search requests are not handled in Maps SDK for Android at
the current version and an internal error is reported.

You are here