Getting started with here-api – Initializing the Map Fragment

When you have defined the basic layout of the application and acquired necessary permissions, the final step is to initialize the instance of the MapFragment class, thus creating and associating a Map with the MapFragment declared in the activity_main.xml file.

public class BasicMapActivity extends Activity {

  // map embedded in the map fragment
  private Map map = null;

  // map fragment embedded in this activity
  private MapFragment mapFragment = null;

  public void onCreate(Bundle savedInstanceState) {

  private void initialize() {

    mapFragment = (MapFragment)getFragmentManager().findFragmentById(;
    mapFragment.init(new OnEngineInitListener() {
      public void onEngineInitializationCompleted(OnEngineInitListener.Error error)
        if (error == OnEngineInitListener.Error.NONE) {
          map = mapFragment.getMap();  
          map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0),
            (map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
        } else {
          System.out.println("ERROR: Cannot initialize Map Fragment");

if you want to reproduce, please indicate the source:
Getting started with here-api – Initializing the Map Fragment - CodeDay