Quickstart
The Search module provides a set of tools to add a search experience to your application. With it, you can build an interface for users to perform single-line fuzzy searches for addresses and POIs using the TomTom Search APIs.
Project set up
To use the Search module, you need to configure its credentials and add the module as a dependency:
- Get your TomTom API key from the Developer Portal. You can find instructions on how to do that here.
- Configure the project as described in the Project setup guide.
- Add the
Search
module dependency in thebuild.gradle
of your application module and synchronize the project.1dependencies {2 implementation "com.tomtom.sdk.search:search-online:0.3.1617"3}
After synchronizing the project, initialize the Search
object. This object is the entry point to using TomTom’s Search module.
val searchApi = OnlineSearch.create(context, "YOUR_API_KEY")
Making search calls
Each search call can be done either synchronously or asynchronously.
Synchronous calls
Synchronous calls are useful when you want to have full control over the threading model used in your application. Note that search calls block execution, so they must be done off the main thread. Otherwise, an exception is thrown.
The response to the request is packed in the Result<SuccessType, FailureType>
class. Use the Result.isSuccess()
method to check if the call succeeded. If the method returns true, you can get the result of the request using the Result.value()
method. If an error occurred, Result.isFailure()
returns true instead. More details about the error can be found using Result.failure()
.
1val query = "TomTom"2val searchOptions = SearchOptions(query = query, limit = 5)3val result = search.search(searchOptions)
Asynchronous
An asynchronous call requires an appropriate callback to be provided as a parameter to the request. See the code for an example of what is required. If the call is successful, the callback’s onSuccess(result: SearchResponse)
method is triggered with the search result. If a failure occurred, it is provided by the callback’s onFailure(failure: SearchFailure)
method.
1val query = "TomTom"2val searchOptions = SearchOptions(query = query, limit = 5)3search.search(4 searchOptions,5 object : SearchCallback {6 override fun onSuccess(result: SearchResponse) {7 /* YOUR CODE GOES HERE */8 }910 override fun onFailure(failure: SearchFailure) {11 /* YOUR CODE GOES HERE */12 }13 }14)

Next steps
Since you have learned the basics of searching, here are recommendations for the next steps: