Map stays green / "blank"

Hi there,

I am a newbie to tomtom Maps. Currently I am trying to simply display a map in an activity. However, when running the app, the map stays green.
Could someone maybe help me?
Thanks a lot!!

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.tomtom.online.sdk.map.MapFragment;
import com.tomtom.online.sdk.map.OnMapReadyCallback;
import com.tomtom.online.sdk.map.TomtomMap;
import com.tomtom.online.sdk.map.model.MapTilesType;


public class Main2Activity extends AppCompatActivity {
    private TextView txt1, txt2;
    private ImageButton back, forth;
    private TomtomMap tomtomMap;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        MapFragment mapFragment = (MapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);
        mapFragment.getAsyncMap(onMapReadyCallback);
        


        txt1 = findViewById(R.id.parkName);
        txt2 = findViewById(R.id.distance);
        back = findViewById(R.id.imageButtonback);
        forth = findViewById(R.id.imageButtonforth);

        back.setVisibility(View.INVISIBLE);

        //deleteDatabase("quotes.db");
        DatabaseAccess databaseAccess = DatabaseAccess.getInstance(this);

        databaseAccess.open();

        Double dist = Double.valueOf(databaseAccess.getHits(0,4))/1000;
        txt1.setText(databaseAccess.getHits(0, 1 ));
        txt2.setText(String.format("%.1f", dist) + " km");
        databaseAccess.close();

        forth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Main2Activity.this, Main3Activity.class);

                startActivity(intent);
            }
        });

    }
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        tomtomMap.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    private final OnMapReadyCallback onMapReadyCallback =
            new OnMapReadyCallback() {
                @Override
                public void onMapReady(TomtomMap map) {
                    //Map is ready here
                    tomtomMap = map;
                    tomtomMap.setMyLocationEnabled(true);

                }
            };


}

Hi.

You can try to check our tutorial: https://developer.tomtom.com/maps-sdk-android/android-tutorials-use-cases/search-along-route

You can also share your AndroidManifest.xml file and your layout of your Main2Activity so that we will be able to help you quicker.

Regards,
Mateusz

Hi Mateusz, thanks.

I found the reason for the issue: I had put the meta data not within the application but above. Therefore, the API key was not found I guess.

Regards,
Simon

1 Like