MapDownloader
public class MapDownloader
extension MapDownloader: NativeBase
extension MapDownloader: Hashable
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 MapDownloader.fromEngineAsync(...).
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.
-
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.
Declaration
Swift
public var taskCount: UInt32 { get set } -
Gets a single instance of this class per provided
SDKNativeEngine.Declaration
Swift
public static func fromEngineAsync(_ sdkEngine: SDKNativeEngine, _ mapDownloaderConstructionCallback: @escaping MapDownloaderConstructionHandle)Parameters
sdkEngineAn instance of the SDKNativeEngine
mapDownloaderConstructionCallbackA callback that will receive the result of construction
-
Performs an asynchronous request to fetch a list of
Regionobjects for downloading map data in a separate request.The default language for
Region.nameisLanguageCode.enUs.Declaration
Swift
@discardableResult public func getDownloadableRegions(completion: @escaping CompletionHandler) -> TaskHandleParameters
completionCallback which receives the result on the main thread.
Return Value
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
Performs an asynchronous request to fetch a list of
Regionobjects withRegion.namein givenMapDownloader.getDownloadableRegions(LanguageCode, CompletionHandler).languageCode, that can be used to download the actual map data in a separate request.Declaration
Swift
@discardableResult public func getDownloadableRegions(languageCode: LanguageCode, completion: @escaping CompletionHandler) -> TaskHandleParameters
languageCodeThe language code determines the language of
Region.name.completionCallback which receives the result on the main thread.
Return Value
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
Performs an asynchronous request to download map data for regions specified by a list of
RegionIdinstances.MapDownloader.downloadRegions(...).statusListenerreceives notifications untilonDownloadRegionsComplete(...)is called. The returnedMapDownloaderTaskcan be used to pause or resume the download usingMapDownloaderTask.pause(Bool)orMapDownloaderTask.resume(...).To cancel the request, call
MapDownloaderTask.cancel(...)on the returnedMapDownloaderTaskobject. After cancellation,onDownloadRegionsComplete(...)is called with the errorMapLoaderError.operationCancelled.MapDownloaderTaskremains operational untilonDownloadRegionsComplete(...)is called.To get list of downloadable regions use
MapDownloader.getDownloadableRegions(LanguageCode, CompletionHandler)API.Simultaneous downloads of the same region are not supported. If this occurs,
onDownloadRegionsComplete(...)is called withMapLoaderError.serviceAccessFailedfor 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.Declaration
Swift
@discardableResult public func downloadRegions(regions: [RegionId], statusListener: DownloadRegionsStatusListener) -> MapDownloaderTaskReturn Value
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
Performs an asynchronous request to download map data for area specified by a GeoPolygon.
MapDownloader.downloadArea(...).statusListeneris receiving notifications untilonDownloadRegionsComplete(...)is called. ReturnedMapDownloaderTaskshould be used to pause or resume started download, by invokingMapDownloaderTask.pause(Bool)orMapDownloaderTask.resume(...). Request can be cancelled by callingMapDownloaderTask.cancel(...)on returnedMapDownloaderTaskobject, afterwardsonDownloadRegionsComplete(...)is called with errorMapLoaderError.operationCancelled.MapDownloaderTaskremains operational untilonDownloadRegionsComplete(...)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
onDownloadRegionsComplete(...)is called with errorMapLoaderError.serviceAccessFailedfor 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.Declaration
Swift
public func downloadArea(area: GeoPolygon, statusListener: DownloadRegionsStatusListener) -> MapDownloaderTaskReturn Value
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.
-
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.internalError. Also, deleting a region when there is an ongoing download returns errorMapLoaderError.parallelRequest.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.Declaration
Swift
public func deleteRegions(regions: [RegionId], completion: @escaping DeleteRegionsCompletionHandler)Parameters
regionsList of regions to be deleted.
completionCallback which receives the result of deletion on the main thread.
-
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
MapDownloader.downloadRegions(...)to learn more about index.Declaration
Swift
public func clearPersistentMapStorage(completion: @escaping CacheCallbackCompletionHandler)Parameters
completionCallback which receives the result of clearing on the main thread.
-
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.
Throws
MapLoaderExceptionSpecifies reason, why list of installed regions is not returned.Declaration
Swift
public func getInstalledRegions() throws -> [InstalledRegion]Return Value
List of IDs of regions that are installed on the device
- successfully downloaded regions, indicated by
-
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.Declaration
Swift
public func getInitialPersistentMapStatus() -> PersistentMapStatusReturn Value
Initial status of the persistent map.
-
Tries to repair already downloaded regions that are in a corrupted state (see
MapDownloader.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.Declaration
Swift
public func repairPersistentMap(completion: @escaping RepairCompletionHandler)Parameters
completionA callback which receives the result of the repair operation on the main thread.
-
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.Throws
MapLoaderExceptionSpecifies reason, why current map size is not returned.Declaration
Swift
public func getOfflineMapsStorageSizeInBytes() throws -> UInt64Return Value
Value of offline map size.
-
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.Declaration
Swift
public func getOfflineMapsStorageSizeInBytes(completion: @escaping OfflineStorageSizeHandler) -> TaskHandleParameters
completionA callback which receives the value of offline map size or error on the main thread.
Return Value
Handle that will be used to manipulate the execution of the task, for example, to cancel on ongoing request.