Com.tomtom.sdk:maps-display:0.3.344 sample code

Hi all,

Are there any newer sample code available for the maps version 0.3.344 ?
I am looking for sample code for Marker with clustering implementation in Java.
This sample tomtom-international - map-sdk-for-android-examples on GitHub does not seem to be
compiling properly, deprecated ?

Thanks,
Ewan

Hello,

Most up-to-date examples are published in the developer portal.
You can find Markers for Android SDK here:

If you have any more questions, feel free to reply.

Hi,
Thank you very much for your response. I have created my TomTom app framework from the following link to display the map and it works just fine.

Then I decided to add map marker to the map from the code you have shown me earlier but I encountered a bunch of errors which are not related to missing import . I’m kinda stucked at this point and do not know how to proceed further. Could you please lend me a helping hands and points me in the correct direction as currently I am at a total lost in this map marker thing…
I have included my build.gradle (module), the main source file MapFragment.java for your reference.

[MapFragment.java]

package com.example.ttmapstuff;

import android.graphics.drawable.Icon;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import android.provider.CallLog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.tomtom.sdk.maps.display.TomTomMap;
//import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.tomtom.sdk.maps.display.MapOptions;
import com.tomtom.sdk.common.location.GeoCoordinate;
import com.tomtom.sdk.maps.display.camera.CameraOptions;
import com.tomtom.sdk.maps.display.camera.CameraPosition;
import com.tomtom.sdk.maps.display.image.Image;
import com.tomtom.sdk.maps.display.image.ImageFactory;
import com.tomtom.sdk.maps.display.marker.Marker;
import com.tomtom.sdk.maps.display.marker.MarkerOptions;

import timber.log.Timber;

[build.gradle:module]

dependencies {
implementation “com.tomtom.sdk:maps-display:0.3.344”
implementation “com.tomtom.sdk:location-android:0.3.344”
implementation “com.tomtom.sdk:search-client-online:0.3.344”
implementation “com.tomtom.sdk:routing-client-online:0.3.344”

implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

}

Thank You,
Ewan

1 Like

Using ImageFactory requires using INSTANCE as well.
Therefore, the invocation should look like this:

ImageFactory.INSTANCE.fromResource(...)

We can also see that you are mixing the Java class with Kotlin code.

Thank you very much for the tips! that sure works for ImageFactory now…
Regarding the Kotlin code in Java I have no other choice since my main program was written purely in Java code only and the map is my last module to be integrated with it. TTMapStuff was just a simplified framework for testing of TomTom map Android SDK before exporting the code to the main program.
What would the code looked like in Android Java for the following TomTom code ?

val amsterdam = GeoCoordinate(52.379189, 4.899431)
val markerOptions = MarkerOptions(
coordinate = amsterdam,
pinImage = ImageFactory.fromResource(R.drawable.ic_marker_pin)
)

Currently, on my Android Studio Chipmunk 2021.2.1 Patch 1 the error looks like this…

The problems appears to be in the R.drawable.markerpin_foreground

Also, I am a complete newbie with Kotlin…

Please respond,
Thank you very much!
Ewan

Hi again,

Regarding MarkerOptions, you need to write down all arguments when using Java.
You can see default values here

The @Override issue looks like you didn’t declare the OnMapReadyCallback implementation on this class.

Hi,
Ok, noted!
Thank you very much!!!

Hi,

These declarations got rid of all my previous errors.

@Override
public void onMapReady(@NonNull TomTomMap tomTomMap) {
    TomTomMap ttmap = null;
    GeoCoordinate amsterdam = new GeoCoordinate(52.379189, 4.899431);
    GeoCoordinate coordinate;
    Image pinImage;
    Object markerOptions;
    Image pinIconImage;
    Image shieldImage;

    Object tag;
    Label label;
    String balloonText;

    markerOptions = new MarkerOptions(
            coordinate = amsterdam,
            pinImage = ImageFactory.INSTANCE.fromResource(R.drawable.markerpin_foreground),
            pinIconImage = null,
            shieldImage = null,
            tag         = null,
            label       = null,
            balloonText = "Bahloon"
    );
    //ttmap.addMarker((MarkerOptions) markerOptions);
  
}

As for the OnMapReadyCallback I declared it on the fragment class like so…

public class MapFragment extends Fragment implements com.tomtom.sdk.maps.display.ui.OnMapReadyCallback {

From here I just right clicked on the above line and then clicked the ‘implement’ that generate the below function

@Override
public void onMapReady(@NonNull TomTomMap tomTomMap)

But this function did not get called when the map is finished loading… why?
Do I have to called the OnMapReadyCallback from the MainActivity instead ?

Also, from your website at the end of the page

Where is the function getMapAsync() hidden at ? I can’t seem to be able to located this function at all !!!

Thank You very much!
Ewan

Hi All,

Now I’m getting this error in the getMapAsync() function
error: incompatible types: cannot be converted to com.google.android.gms.maps.OnMapReadyCallback
mapFragment.getMapAsync(new com.tomtom.sdk.maps.display.ui.OnMapReadyCallback() {

mapFragment.getMapAsync(new com.tomtom.sdk.maps.display.ui.OnMapReadyCallback() { });
if I switched the above to
mapFragment.getMapAsync(new OnMapReadyCallback() { });
and
@Override
public void onMapReady(@NonNull TomTomMap tomTomMap) {}
to
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {}

essentially back to Google Map those errors went away.

My question is, how to I go about keeping TomTom map in the code without causing those red error lines ?

Thanks,
Ewan

Hi,
In line 49, you are casting to SupportMapFragment, which is Google’s.
You should cast to TomTom’s MapFragment class. Assuming you already declared the fragment correctly in the layout.xml (with the android:name attribute).

Hi,
The reason for the used of SupportMapFragment is the access to member function getMapAsync().
With MapFragment there isn’t any member function named getMapAsync() !? From my understanding getMapAsync() is the entry point to onMapReady() ?. If this is the case then where is getMapAsync() in MapFragment ?

The following is my fragment_map.xml

<?xml version="1.0" encoding="utf-8"?>

<androidx.fragment.app.FragmentContainerView xmlns:tomtom=“http://schemas.android.com/apk/res-auto
xmlns:android=“http://schemas.android.com/apk/res/android
android:id="@+id/map_fragment"
android:name=“com.tomtom.sdk.maps.display.ui.MapFragment”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tomtom:mapKey=“1234567890” />

Thanks again,
Ewan