MapDownloader (API Reference)
Class MapDownloader
A class for downloading and managing map data for various regions worldwide.
Downloaded map data is permanently stored on disk, enabling maps at all zoom levels,
search, routing, and other features without an active data connection.
Users can query available regions, download them to disk, or delete them.
An instance of this class can be created using fromEngineAsync(com.here.sdk.core.engine.SDKNativeEngine, com.here.sdk.maploader.MapDownloaderConstructionCallback).
The storage path for downloaded maps can be specified via SDKOptions.persistentMapStoragePath.
To control the type of content included in a map download, use LayerConfiguration.
Once applied, it affects both the map cache and offline maps.
Satellite-based map schemes are not included in the downloaded region data.
Note:
During turn-by-turn navigation,
while a map download or update is in progress, navigation may not function as expected,
and the app may be blocked until the operation is completed.
Ensure that all pending map operations are finished before starting navigation.
This applies only to MapDownloader and MapUpdater. RoutePrefetcher operations are not affected.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclearPersistentMapStorage(SDKCacheCallback callback) Performs an asynchronous operation to clear the persistent map storage from all data.voiddeleteRegions(List<RegionId> regions, DeletedRegionsCallback callback) Performs an asynchronous operation to delete map data for regions specified by a list ofRegionId.downloadArea(GeoPolygon area, DownloadRegionsStatusListener statusListener) Performs an asynchronous request to download map data for area specified by a GeoPolygon.downloadRegions(List<RegionId> regions, DownloadRegionsStatusListener statusListener) Performs an asynchronous request to download map data for regions specified by a list ofRegionIdinstances.static voidfromEngineAsync(SDKNativeEngine sdkEngine, MapDownloaderConstructionCallback mapDownloaderConstructionCallback) Gets a single instance of this class per providedSDKNativeEngine.getDownloadableRegions(LanguageCode languageCode, DownloadableRegionsCallback callback) Performs an asynchronous request to fetch a list ofRegionobjects withRegion.namein givenlanguageCode, that can be used to download the actual map data in a separate request.Performs an asynchronous request to fetch a list ofRegionobjects for downloading map data in a separate request.Gets the initial status of the already downloaded regions at start-up time of the app.Method to get a list of map regions that are currently installed on the device.longGet the total size of all downloaded regions currently persisted on disk at the location that is specified viaSDKOptions.persistentMapStoragePath.Get the total size of all downloaded regions currently persisted on disk at the location that is specified viaSDKOptions.persistentMapStoragePath.longGets the number of concurrent tasks for downloading a map.voidDeprecated.Only part of Internal variant.voidTries to repair already downloaded regions that are in a corrupted state (seegetInitialPersistentMapStatus()).voidsetTaskCount(long value) Sets the number of concurrent tasks for downloading a map.
-
Method Details
-
fromEngineAsync
public static void fromEngineAsync(@NonNull SDKNativeEngine sdkEngine, @NonNull MapDownloaderConstructionCallback mapDownloaderConstructionCallback) Gets a single instance of this class per provided
SDKNativeEngine.- Parameters:
sdkEngine-An instance of the SDKNativeEngine
mapDownloaderConstructionCallback-A callback that will receive the result of construction
-
getDownloadableRegions
Performs an asynchronous request to fetch a list of
Regionobjects for downloading map data in a separate request.The default language for
Region.nameisLanguageCode.EN_US.- Parameters:
callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
getDownloadableRegions
@NonNull public TaskHandle getDownloadableRegions(@NonNull LanguageCode languageCode, @NonNull DownloadableRegionsCallback callback) Performs an asynchronous request to fetch a list of
Regionobjects withRegion.namein givenlanguageCode, that can be used to download the actual map data in a separate request.- Parameters:
languageCode-The language code determines the language of
Region.name.callback-Callback which receives the result on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
downloadRegions
@NonNull public MapDownloaderTask downloadRegions(@NonNull List<RegionId> regions, @NonNull DownloadRegionsStatusListener statusListener) Performs an asynchronous request to download map data for regions specified by a list of
RegionIdinstances.statusListenerreceives notifications untilDownloadRegionsStatusListener.onDownloadRegionsComplete(com.here.sdk.maploader.MapLoaderError, java.util.List<com.here.sdk.maploader.RegionId>)is called. The returnedMapDownloaderTaskcan be used to pause or resume the download usingMapDownloaderTask.pause(boolean)orMapDownloaderTask.resume().To cancel the request, call
MapDownloaderTask.cancel()on the returnedMapDownloaderTaskobject. After cancellation,DownloadRegionsStatusListener.onDownloadRegionsComplete(com.here.sdk.maploader.MapLoaderError, java.util.List<com.here.sdk.maploader.RegionId>)is called with the errorMapLoaderError.OPERATION_CANCELLED.MapDownloaderTaskremains operational untilDownloadRegionsStatusListener.onDownloadRegionsComplete(com.here.sdk.maploader.MapLoaderError, java.util.List<com.here.sdk.maploader.RegionId>)is called.To get list of downloadable regions use
getDownloadableRegions(LanguageCode, DownloadableRegionsCallback)API.Simultaneous downloads of the same region are not supported. If this occurs,
DownloadRegionsStatusListener.onDownloadRegionsComplete(com.here.sdk.maploader.MapLoaderError, java.util.List<com.here.sdk.maploader.RegionId>)is called withMapLoaderError.SERVICE_ACCESS_FAILEDfor the new request, while the previous one continues uninterrupted.If indexing is enabled through
OfflineSearchEngine.setIndexOptions, then after the requested regions have been downloaded, the corresponding index will be created. The index is used byOfflineSearchEngineto find better results. Note: Indexing is a beta feature, so there could be a few bugs and unexpected behaviors.To control list of map content features for region download, use
LayerConfiguration.enabledFeatures.
Note: If an application is forcefully closed or crashes during a map download operation, then this method can be called again to resume the download. For example, if a download was interrupted at 60%, then the next call to download the same region will load the remaining 40%.
Note: If a download fails during runtime, then the HERE SDK will automatically retry to download the affected region three times before giving up. A connection will be timed out after one minute.- Parameters:
regions-List of regions to download. Can be fetched using
getDownloadableRegions(LanguageCode, DownloadableRegionsCallback)API.statusListener-Notifies on the download progress.
- Returns:
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
downloadArea
@NonNull public MapDownloaderTask downloadArea(@NonNull GeoPolygon area, @NonNull DownloadRegionsStatusListener statusListener) Performs an asynchronous request to download map data for area specified by a GeoPolygon.
statusListeneris receiving notifications untilDownloadRegionsStatusListener.onDownloadRegionsComplete(com.here.sdk.maploader.MapLoaderError, java.util.List<com.here.sdk.maploader.RegionId>)is called. ReturnedMapDownloaderTaskshould be used to pause or resume started download, by invokingMapDownloaderTask.pause(boolean)orMapDownloaderTask.resume(). Request can be cancelled by callingMapDownloaderTask.cancel()on returnedMapDownloaderTaskobject, afterwardsDownloadRegionsStatusListener.onDownloadRegionsComplete(com.here.sdk.maploader.MapLoaderError, java.util.List<com.here.sdk.maploader.RegionId>)is called with errorMapLoaderError.OPERATION_CANCELLED.MapDownloaderTaskremains operational untilDownloadRegionsStatusListener.onDownloadRegionsComplete(com.here.sdk.maploader.MapLoaderError, java.util.List<com.here.sdk.maploader.RegionId>)is called.Downloaded area will be associated to a unique id that will be reported via
DownloadRegionsStatusListener.Simultaneous download of the same region twice is not supported. When such condition occurs then
DownloadRegionsStatusListener.onDownloadRegionsComplete(com.here.sdk.maploader.MapLoaderError, java.util.List<com.here.sdk.maploader.RegionId>)is called with errorMapLoaderError.SERVICE_ACCESS_FAILEDfor a new request, while previous one continues uninterrupted.If indexing is enabled through
OfflineSearchEngine.setIndexOptions, then after the requested regions have been downloaded, the corresponding index will be created. The index is used byOfflineSearchEngineto find better results. Note: Indexing is a beta feature, so there could be a few bugs and unexpected behaviors.To control list of map content features for area download, use
LayerConfiguration.enabledFeatures.
Note: If an application is forcefully closed or crashes during a map download operation, then this method can be called again to resume the download. For example, if a download was interrupted at 60%, then the next call to download the same region will load the remaining 40%.
Note: If a download fails during runtime, then the HERE SDK will automatically retry to download the affected region three times before giving up. A connection will be timed out after one minute.
Note: If user try to re-download same GeoPolygon the status will be reported as per the state of previous download operation.- Parameters:
area-Area to download.
statusListener-Notifies on the download progress.
- Returns:
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
deleteRegions
public void deleteRegions(@NonNull List<RegionId> regions, @NonNull DeletedRegionsCallback callback) Performs an asynchronous operation to delete map data for regions specified by a list of
RegionId. Note: Deleting a region when there is a pending download returns errorMapLoaderError.INTERNAL_ERROR. Also, deleting a region when there is an ongoing download returns errorMapLoaderError.PARALLEL_REQUEST.If indexing is enabled through
OfflineSearchEngine.setIndexOptions, then after the requested regions have been deleted, the index over remaining regions will be rebuilt, so that entries related to deleted regions are removed. The index is used byOfflineSearchEngineto find better results. Note: Indexing is a beta feature, so there could be a few bugs and unexpected behaviors.- Parameters:
regions-List of regions to be deleted.
callback-Callback which receives the result of deletion on the main thread.
-
clearPersistentMapStorage
Performs an asynchronous operation to clear the persistent map storage from all data. All downloaded regions will be removed. Note: Must be called only when no other region operation is ongoing. Returns an error if there is any active operation.
Any previously built index will also be deleted. See
downloadRegions(java.util.List<com.here.sdk.maploader.RegionId>, com.here.sdk.maploader.DownloadRegionsStatusListener)to learn more about index.- Parameters:
callback-Callback which receives the result of clearing on the main thread.
-
getInstalledRegions
Method to get a list of map regions that are currently installed on the device. Throws if it's not possible to return list of installed regions. Returned list contains:
- successfully downloaded regions, indicated by
InstalledRegionStatus.INSTALLEDinInstalledRegion.status; - regions, that are in the download process, indicated by
InstalledRegionStatus.PENDINGinInstalledRegion.status; - regions, which were failed to be downloaded, indicated by
InstalledRegionStatus.PENDINGinInstalledRegion.status. Note: precise Japan content is stored in separate catalog on the HERE platform, and when corresponding region is downloaded, then the status of siblings and parent regions is set to theInstalledRegionStatus.PENDINGinInstalledRegion.status. Precise Japan content is available as an additional offering, please contact sales team for more information.
- Returns:
List of IDs of regions that are installed on the device
- Throws:
MapLoaderException-Specifies reason, why list of installed regions is not returned.
- successfully downloaded regions, indicated by
-
getInitialPersistentMapStatus
Gets the initial status of the already downloaded regions at start-up time of the app. It is not recommended to download or to upload map data while an app is running in background. However, it can happen, that an app gets shut down during an ongoing operation, for example, due to a crash. In such a case, some or all of the downloaded map data may be in a corrupted state. Refer to the
PersistentMapStatusfor exact healing procedure for specific status. Note: This value will not change during the lifetime of an app.- Returns:
Initial status of the persistent map.
-
repairPersistentMap
Tries to repair already downloaded regions that are in a corrupted state (see
getInitialPersistentMapStatus()).If indexing is enabled through
OfflineSearchEngine.setIndexOptions, then index will be rebuilt if existing index does not match with the installed map regions after this operation. The index is used byOfflineSearchEngineto find better results. Note: Indexing is a beta feature, so there could be a few bugs and unexpected behaviors.- Parameters:
callback-A callback which receives the result of the repair operation on the main thread.
-
getOfflineMapsStorageSizeInBytes
Get the total size of all downloaded regions currently persisted on disk at the location that is specified via
SDKOptions.persistentMapStoragePath. This includes also data that is currently being downloaded.- Returns:
Value of offline map size.
- Throws:
MapLoaderException-Specifies reason, why current map size is not returned.
-
getOfflineMapsStorageSizeInBytes
@NonNull public TaskHandle getOfflineMapsStorageSizeInBytes(@NonNull OfflineStorageSizeCallback callback) Get the total size of all downloaded regions currently persisted on disk at the location that is specified via
SDKOptions.persistentMapStoragePath. This includes also data that is currently being downloaded.- Parameters:
callback-A callback which receives the value of offline map size or error on the main thread.
- Returns:
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
onEnterForeground
Deprecated.Only part of Internal variant. Please use
sdk.maploader.BackgroundMapOperationContext.onEnterForegroundinstead.To enable background map downloads for iOS, this method must be invoked when the application moves from the foreground to the background, usually triggered when the user switches to another application or when the device's screen is turned off. Please note that this method is only relevant to the iOS platform. Robust handling of online requests finished while in the background depends on the integration with AppDelegate. How to integrate it see
sdk.maploader.BackgroundMapOperationContext. -
getTaskCount
public long getTaskCount()Gets the number of concurrent tasks for downloading a map.
A valid task count is between 1 to 64. When the value set is outside the valid range, then it is clamped to a valid range:
- when passed in value is 0 or less, then task count is set to 1;
- when passed in value is 65 or more, then task count is set to 64.
- Returns:
The number of concurrent tasks for downloading a map.
-
setTaskCount
public void setTaskCount(long value) Sets the number of concurrent tasks for downloading a map.
A valid task count is between 1 to 64. When the value set is outside the valid range, then it is clamped to a valid range:
- when passed in value is 0 or less, then task count is set to 1;
- when passed in value is 65 or more, then task count is set to 64.
- Parameters:
value-The number of concurrent tasks for downloading a map.
-