Add Map Api Key Programatically


How can i add the Api Key to the map programatically? i tried the tutorial by adding MapProprieties but i get error could not load title 0/0/0 x0 something, ERROR 403. and the map is empty.

were you trying like on this tutorial Search along a route | Android Tutorials, Use Cases | Maps SDK for Android | TomTom Developer Portal ?

Yes this worked. Thank you! The error was in mapFragment = (MapFragment) getSupportFragmentManger.findFragmentById(;

Map<ApiKeyType, String> mapKeys = new HashMap<>();
  mapKeys.put(ApiKeyType.MAPS_API_KEY,  " your api key ");

  MapProperties mapProperties = new MapProperties.Builder()
  MapFragment mapFragment = MapFragment.newInstance(mapProperties);
          .replace(, mapFragment)
  //for fragment: getChildFragmentManager()
          .replace(, mapFragment)