public final class MapEngine
extends java.lang.Object
MapEngine manages all mapping resources and services provided in this SDK.
MapEngine must be initialized before any of the services can be used. For more
information, see MapEngine.init(ApplicationContext, OnEngineInitListener).
Users can maintain reference count through the use of MapEngine.onPause() and MapEngine.onResume()
thus control when to relinquish MapEngine services.
MapEngine also allows users to subscribe to data download notifications to provide extra
information.
| Modifier and Type | Class and Description |
|---|---|
static class |
MapEngine.MapVariant
Represents supported map variants.
|
static interface |
MapEngine.OnMapDownloadListener
Represents a listener to provide notification upon the start and completion of a data
download event.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addMapDataDownloadListener(MapEngine.OnMapDownloadListener listener)
Adds a
OnMapDownloadListener to listen for map data download events. |
static void |
enableTrafficInOfflineMode(boolean enable)
Allows to use online traffic when
MapEngine is set to OFFLINE. |
static MapEngine |
getInstance()
Returns the MapEngine singleton, if one has already been created.
|
java.lang.String |
getMapApprovalCode(java.util.Locale locale)
Gets map approval code for specific country.
|
java.lang.String |
getProviderCopyrightStatement(java.util.Locale locale)
Gets provider copyright statement for specific country.
|
int |
getResourceReferenceCount()
Get the current reference count of map resource usage for this application.
|
void |
init(ApplicationContext context,
OnEngineInitListener listener)
Asynchronously initialize the
MapEngine. |
static boolean |
isInitialized()
Gets the initialization state of
MapEngine. |
static boolean |
isOnlineEnabled()
Gets the online configuration state of
MapEngine. |
void |
onPause()
Decrements the reference count of map resource usage.
|
void |
onResume()
Increments the reference count of map resource usage.
|
void |
removeMapDataDownloadListener(MapEngine.OnMapDownloadListener listener)
Removes an existing
MapDataDownloadListener. |
static void |
setOnline(boolean online)
Alter the data connectivity mode of the
MapEngine. |
public static MapEngine getInstance()
Once the MapEngine instance is available, it must be initialized through one of the
following methods before it can be used:
MapEngine instancepublic void init(ApplicationContext context, OnEngineInitListener listener)
MapEngine. MapEngine cannot be used until it
has been initialized successfully.
This method is particularly useful for users of headless APIs as the MapEngine is
being automatically initialized as part of the setup process of
AndroidXMapFragments.
This method will initialize MapEngine with ApplicationContext to be used
during initialization.
Users interested in SDK functions such as navigation without initializing a
com.here.android.mpa.mapping.AndroidXMapFragment are responsible for manually calling
MapEngine.onResume() or MapEngine.onPause() to put the MapEngine in
an active state or inactive state, respectively.
context - ApplicationContext to be used during initialization.listener - OnEngineInitListener to provide information when MapEngine
initialization completes and if it has been successful.AndroidXMapFragment.init(OnEngineInitListener),
AndroidXMapFragment.init(ApplicationContext, OnEngineInitListener),
MapEngine.getResourceReferenceCount()com.here.android.mpa.mapping.AndroidXMapFragment are responsible for manually calling
MapEngine.onResume() or MapEngine.onPause() to put the MapEngine
in an active state or inactive state, respectively. Users are also responsible for manually
fetching map data using the MapLoader or the
MapDataPrefetcher.
public int getResourceReferenceCount()
It is very important that an application holds a reference to map resources while in active operation and releases this reference when not in use (e.g. sent to the background). This method is a useful tool to use while developing an application. This value can be logged while testing to ensure that references to map resources are handled properly during the lifecycle of the app.
For users of AndroidXMapFragment class, map resource usage is
handled automatically.
public void onPause()
onPause.
For users of AndroidXMapFragment class, it is not
necessary to call MapEngine.onPause() as it is handled automatically.
public void onResume()
onResume.
For users of AndroidXMapFragment class, it is not
necessary to call MapEngine.onResume() as it is handled automatically.
public void addMapDataDownloadListener(MapEngine.OnMapDownloadListener listener)
OnMapDownloadListener to listen for map data download events.listener - A OnMapDownloadListener to add to the MapEngineMapEngine.removeMapDataDownloadListener(OnMapDownloadListener)public void removeMapDataDownloadListener(MapEngine.OnMapDownloadListener listener)
MapDataDownloadListener.listener - A MapDataDownloadListener to remove from the MapEnginepublic static void setOnline(boolean online)
MapEngine.online - Pass true to set MapEngine connectivity to ONLINE. If
false, connectivity is OFFLINE.
If set to false then the HERE SDK will not access the network to download map
data, perform searches, calculate routes or when providing any other service
unless the service allows overriding this setting, e.g. see
CoreRouter.Connectivity, Request.Connectivity, and
CLE2Request.CLE2ConnectivityMode.
public static boolean isOnlineEnabled()
MapEngine.
If false is returned then the HERE SDK will not access the network to download map data,
perform searches, calculate routes or when providing any other service unless the service
allows overriding this setting, e.g. see
CoreRouter.Connectivity,
Request.Connectivity, and
CLE2Request.CLE2ConnectivityMode.
true if MapEngine is enabled to use network communicationspublic static void enableTrafficInOfflineMode(boolean enable)
MapEngine is set to OFFLINE.enable - Pass true to set traffic connectivity to ONLINE. If false, traffic
connectivity is OFFLINE.java.lang.IllegalStateException - If MapEngine connectivity mode is ONLINE.MapEngine.setOnline(boolean) method resets traffic connectivity mode. Therefore this
method must be called only after MapEngine.setOnline(boolean)., This method must be called only when MapEngine connectivity is set to OFFLINE.
Otherwise IllegalStateException will be thrown.public static boolean isInitialized()
MapEngine.true if MapEngine is initialized and ready for service.public java.lang.String getMapApprovalCode(java.util.Locale locale)
locale - Locale with country code. To create Locale with country use
new Locale(language, country) constructor, or use one of the
predefined locales, e.g. Locale.ENGLISH.java.lang.IllegalArgumentException - if provided locale.getCountry() is null or empty.public java.lang.String getProviderCopyrightStatement(java.util.Locale locale)
locale - Locale with country code. To create Locale with country use
new Locale(language, country) constructor, or use one of the
predefined locales, e.g. Locale.ENGLISH.java.lang.IllegalArgumentException - if provided locale.getCountry() is null or empty.