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

Map initialization

Map initialization

The main class with represents a Map is a MapView. MapView is wrapped by MapFragment.
To display map, MapFragment needs to be attached to layout.

The basic steps for adding a map are:

  1. Follow steps described in "Getting started" section.

  2. Add MapFragment to your Activity (either using the code or layout
    file).

  3. Implement the OnMapReadyCallback and use onMapReady method to get
    the TomtomMap object.

  4. Use the TomtomMap object to set the map properties (e.g. map mode,
    tiles types).

OnMapReadyCallback:

import android.support.annotation.NonNull;

/**
 * Callback interface executed when the map is ready to be used.
 * The instance of this interface is set to {@link MapFragment},
 * and the {@link OnMapReadyCallback#onMapReady(TomtomMap)} is triggered
 * when the map is fully initialized and not-null.
 */
public interface OnMapReadyCallback {
    /**
     * Called when the map is ready to be used.
     */
    void onMapReady(@NonNull TomtomMap tomtomMap);
}

 

Adding the MapFragment to XML file:

<fragment
    android:id="@+id/map_fragment"
    android:name="com.tomtom.online.sdk.map.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

 

Sample implementation of the OnMapReadyCallback:

private final OnMapReadyCallback onMapReadyCallback =
        new OnMapReadyCallback() {
            @Override
            public void onMapReady(TomtomMap map) {
                //Map is ready here
                tomtomMap = map;
                tomtomMap.setMyLocationEnabled(true);
                tomtomMap.collectLogsToFile(SampleApp.LOGCAT_PATH);
            }
        };

MapView initialization.

In some cases, it may be required to use 'MapView' directly, instead of having 'MapFragment'.
In such a case, you need to pass lifecycle events to 'MapView', as shown below:

@Override
/** @inheritDoc */
public void onStart() {
    super.onStart();
    mapView.onStart();
}

@Override
/** @inheritDoc */
public void onResume() {
    super.onResume();
    mapView.onResume();
}

@Override
/** @inheritDoc */
public void onPause() {
    mapView.onPause();
    callbackContainer.removeAllCallbacks();
    super.onPause();
}

@Override
public void onStop() {
    mapView.onStop();
    super.onStop();
}

@Override
public void onDestroy(){
    mapView.onDestroy();
    super.onDestroy();
}

 

When using Maps SDK for Android, it is required that TomTom logo is always visible.
By default, TomTom logo is located at the bottom left corner of the map.
However, you can easily customise its position to meet your app design by define LogoView
style in style.xml in your app.

Sample use case 1: Your app has a bottom panel which covers the TomTom logo and you need to place the logo in top right corner.
To change TomTom logo’s position:

<style name="LogoView" parent="BaseLogoView" >
    <item name="android:layout_gravity">bottom|left</item>
</style>