HERE Android SDK Developer's Guide

MapEngine Class

MapEngine is a singleton class used to manage active mapping resources for use in applications developed with the HERE SDK. MapEngine must be initialized before Map and map-related objects, such as MapMarker and Places, can be instantiated and retrieved from the API. A runtime exception occurs if MapEngine is not properly initialized before map-related objects are used.

Initialization

MapEngine must be initialized before it can be used. MapEngine is automatically initialized for your application by using MapFragment. MapFragment is a fragment class that applications can use as an UI module in an activity for map display. However, if your application does not use MapFragment classes, then the application should initialize the MapEngine directly before using any HERE APIs. You can do this by calling MapEngine.init(ApplicationContext, OnEngineInitListener) as shown below:

MapEngine mapEngine = MapEngine.getInstance();
ApplicationContext appContext = new ApplicationContext(context);
mapEngine.init(appContext, new OnEngineInitListener() {
  @Override
  public void onEngineInitializatonCompleted(Error error) {
    if (error == OnEngineInitListener.Error.NONE) {
      // Post initialization code goes here
    } else {
      // handle factory initialization failure
    }
  }
});

If map engine initialization is in progress or has failed, calling any other HERE SDK APIs fails because invalid objects cannot be created. To avoid this problem, check for MapEngine.isInitialized() in your app lifecycle callbacks. For example, the following example avoids problems with using the PositionManager before an instance can be properly created:

public void onDestroy()
{
  //Set initComplete using MapEngine.isInitialized()
  if (initComplete) {
    PositioningManager.getInstance().removeListener(this);
  }
  super.onDestroy();
}

For examples of typical scenarios using the MapFragment that automatically initializes the MapEngine, see Maps.