Android Project Setup for the TomTom Maps SDK

This article will guide you through the process of setting up a basic Android project that integrates the TomTom Maps SDK for Android and TomTom API services.

To illustrate the project setup process, we’ll create a basic app that displays a map with the user’s current position marked. The app uses the TomTom Search API to let a user search for a point of interest by entering text and returns useful results even if the search includes spelling errors or inexact addresses. The results will be marked on the map for the user to browse.

This example Android application provides a jumping off point for many potential location-aware apps using TomTom location services.

Getting Started

The TomTom Maps SDK for Android is supported on devices running Android version 4.4 (KitKat) or later. I’m going to use Android Studio as my IDE and Java as the development language. Kotlin is also supported.

To use the TomTom SDK and API services, you need a free developer account. Sign up or log in at This account will be used to manage the API keys for the application, and you’ll need an API key with what you build today.

In the TomTom developer portal, go to your dashboard. When you create a new application entry, you’ll be prompted for a name for the application and for the services the application needs. Enter any name you like. You can select any of the API services that apply to your application, but they must be selected to work with your application.

For this example, select Maps API and Search API, as indicated in the screenshot. The Maps SDK contains classes that will handle making the web calls and rendering the map.

Click “Create App” to create the application entry.

Once you’ve saved the application, the dashboard will show an entry for it, and if you click on the entry, you’ll see the “Consumer API Key.” You’ll need this value to authorize API access in your app. We’ll show you how to use the key in your app in a moment.

Android Project Setup

Create a new project in Android Studio. From the “Choose your Project” window, select “Empty Activity” and click “Next,” then enter a name for the project and modify any other project details as needed.

Note that the API version must be no lower than 4.4 (KitKat). Click “Finish” to create the project.

We’ve created the project, but there’s still some configuration to do before diving into the code.

We’ll need the API keys for the services we’re using.

Find the application manifest in the left pane (AndroidManifest.xml). Within the <application/> node of the file, add <meta-data /> entries for the application keys. For the sample app we only need keys for the OnlineMaps.Key and OnlineSearch.Key, but I’ve included the names of other possible <meta-data /> elements you might use with other SDKs:

					<meta-data android_name="OnlineMaps.Key" android_value="YOUR_KEY_HERE" />
<meta-data android_name="OnlineSearch.Key" android_value=" YOUR_KEY_HERE " />
<meta-data android_name="OnlineTraffic.Key" android_value=" YOUR_KEY_HERE " />
<meta-data android_name="OnlineRouting.Key" android_value=" YOUR_KEY_HERE " />
<meta-data android_name="GeofencingApi.Key" android_value=" YOUR_KEY_HERE " />

In the left pane in Android Studio, you’ll see two entries for build.gradle, one for Project and the other for Module. Double-click on the build.gradle file for the project, which contains a section for allprojects. Within allprojects you’ll see an entry for repositories, which already contains a couple of entries. We’ll add a third entry so the IDE can retrieve components of the SDK, as shown below in bold:

					allprojects {
    repositories {
        maven {
            url ''

Save and close the file.

Now open the build.gradle file for the module. In the dependencies block, add entries referencing both the Maps and Search SDKs. We only need those two here, but I show other possible entries for other SDK components, commented out.

The number at the end of these strings is the SDK version. I’m using 2.4.37. Note that when you’re using more than one component, the SDK versions must be the same for all components. We also need to enable multidex in the implementation to avoid a limitation about including libraries that we’d otherwise encounter.

					implementation ''
// These entries could be used for other TomTom services

Next, we’ll add a section called compileOptions to the android section of the file, to set sourceCompatibility and targetCompatibility for Java Version 1.8. We also need to set the multidex setting to true. The additions are shown in bold:

					android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.tomtommapstestapp"
        minSdkVersion 19
        targetSdkVersion 29
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), ''

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8

With this done, the configuration is complete. You can compile the application. Just take an extra look to make sure you don’t encounter any errors resulting from mistyping.

Now that we’ve completed the setup, let’s write more of the actual code.

Building the UI

The application already has a layout file named activity_main.xml. This is where we’ll define the application UI. Remove the “Hello World” text element and add a <fragment /> element for the map view instead:

    tools_layout="@layout/map_view" />

If you run the application now, you’ll see a map of the earth in which you can zoom and scroll.


The UI will need additional elements for text entry for the search and to show the results as a list. I added an EditText element for the text entry and a ListView to show the list of search results.

In the, we need a few variables to hold references to the map object, the search service, the search results, and the adapter for the list view:

					TomtomMap tomtomMap;
SearchService tomtomSearch;
ImmutableList<FuzzySearchResult> lastSearchResult;
ResultListAdapter adapter;

After the activity’s content view is initialized, in onCreate we use a reference to the map fragment to request a map object. When the map is ready, our callback is called and given a reference to the map. We save the reference since we’ll need it for other calls to the map.

Notice a pattern throughout this code: requests being asynchronous and being notified of their completion with results in callbacks.

					MapFragment mapFragment = (MapFragment)getSupportFragmentManager().findFragmentById(;
Log.d(TAG, "Request map from map fragment");
mapFragment.getAsyncMap(new OnMapReadyCallback() {
    public void onMapReady(@NonNull TomtomMap map) {
        Log.d(TAG, "Map retrieved");
        tomtomMap = map;
        //Set the map view somewhere near San Jose
        tomtomMap.centerOn(37, -121, 8);

We use the SearchServiceManager class to create our SearchService object. As with the map object, we use a callback to get the SearchService object:

					Log.d(TAG, "Requesting search service");
ServiceConnection serviceConnection = SearchServiceManager.createAndBind(getBaseContext(),
        new SearchServiceConnectionCallback() {
            public void onBindSearchService(SearchService searchService) {
                Log.d(TAG,"Search service retrieved");
                tomtomSearch = searchService;

We want the search results to be based on the part of the map the user is viewing. When the user presses the search button, the coordinates for the map center can be found by calling getCenterOfMap() on the map object. 

The center coordinates and the text the user enters in the search box are both added to a FuzzySearchQuery object, and the fuzzy search service will look for relevant results. The query object is passed to the Search object that was created earlier. 

Search is performed asynchronously. When it completes, the code receives a callback with the search response.

					EditText searchEditText = findViewById(;
searchEditText.setOnEditorActionListener((v, actionId, event) -> {
    LatLng mapCenter = tomtomMap.getCenterOfMap();

    FuzzySearchQuery searchQuery = FuzzySearchQueryBuilder.create(v.getText().toString())
        .build();, new FuzzySearchResultListener() {
        public void onSearchResult(FuzzySearchResponse fuzzySearchResponse) {
            ImmutableList<FuzzySearchResult> results = fuzzySearchResponse.getResults();
        public void onSearchError(SearchError searchError) {

For a successful search, we’ll display a list of the results on the screen using ListView functionality. We only need to let the adapter for the ListView know that the data to display has been updated. If there is an unsuccessful search we get back an empty result set. If this happens we show a brief notification to let the user know.

We also want markers for the search results to be placed on the map, so we’ll use the Maps SDK’s MarkerBuilder class to create an object that represents a marker on the map. Once the object is built, we can show it on the map by calling addMarker on our map object.

					void showSearchResults(ImmutableList<FuzzySearchResult> resultList)
    Log.i(TAG, resultList.toString());
    this.lastSearchResult = resultList;

    if(this.lastSearchResult.size() == 0)
        Toast.makeText(getBaseContext(), "No locations found", 

    for(int i=0;i<lastSearchResult.size();++i)
        LatLng geoposition = lastSearchResult.get(i).getPosition();
        Poi poi = lastSearchResult.get(i).getPoi();
        MarkerBuilder markerBuilder = new MarkerBuilder(geoposition)
            .markerBalloon(new SimpleMarkerBalloon(poi.getName()))

If someone clicks on an item on the ListView, the map needs to re-center on that item. The centerOn method was used at map initialization to center the map on San Jose, and we can use it again to center the map on the item the user selected:

					searchResultList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        FuzzySearchResult result = 
        LatLng geoposition = result.getPosition();

Deploy the application and try searching for a category, such as "airports" or "hospitals." You should see several results listed, and be able to click on any of them to have the map focus on it. If you see this, you’ve successfully created and configured an application that uses the TomTom Maps SDK and services.


Next Steps

We created a basic Android project that’s configured to use the TomTom Maps SDK and its Search API. Using the SDK, you can build a variety of applications, from ones with customized maps, to ones for tracking assets, for querying traffic information, and for searching an area for points of interest.

Using the same steps, you could create an application that uses TomTom’s other services.

For more information on the TomTom Maps SDK for Android, visit

This article was originally published on TomTom’s blog.

If you’re interested in developing expert technical content that performs, let’s have a conversation



If you work in a tech space and aren’t sure if we cover you, hit the button below to get in touch with us. Tell us a little about your content goals or your project, and we’ll reach back within 2 business days. 

Share via
Copy link
Powered by Social Snap