Map Package Download
The second method of getting offline maps capabilities is enabled through the use of NMAMapLoader
and its associated objects. The NMAMapLoader
class provides a set of APIs that allow manipulation of the map data stored on the device. Operations include:
-
getMapPackages
- To retrieve the current state of the map data on the device through a delegate callback. After this asynchronous operation is complete,rootPackage
property is also populated with the root item of package hierarchy -
getMapPackageAtGeoCoordinates:
- To find the smallestNMAMapPackage
containing a given set of geocoordinates -
installMapPackages:
- To request the specified list ofNMAMapPackage
to be installed -
uninstallMapPackages:
- To request the specified list ofNMAMapPackage
to be uninstalled -
checkForMapDataUpdate
- To check whether a new map data version is available -
getMapDataUpdateSize
- To get the size of a pending map data version update -
performMapDataUpdate
- To perform a map data version update, if available -
cancelCurrentOperation
- To cancel the runningMapLoader
operation
NMAMapLoader
is a singleton which must be obtained using sharedMapLoader
method. The following code example shows basic NMAMapLoader
use:
- Initiate
NMAMaploader
- (void) initMapLoader { NMAMapLoader *mapLoader = [NMAMapLoader sharedMapLoader]; mapLoader.delegate = self; ... [[NMAMapLoader sharedMapLoader] getMapPackages]; ... }
- Install a map package
- (void) startInstall { ... NSArray *packageArray = [[NSArray alloc] initWithObjects:packageToModify, nil]; [[NMAMapLoader sharedMapLoader] installMapPackages:packageArray]; ... }
NMAMapLoader
operations are performed asynchronously. When available, the results of these operations are passed on to the map loader delegate. The delegate is accessed via NMAMapLoader delegate
property, and it must implement the NMAMapLoaderDelegate
protocol. The callbacks of NMAMapLoaderDelegate
protocol are:
-
mapLoader:didUpdateProgress:
- Called duringNMAMapLoader
operations to indicate the current progress of that operation -
mapLoader:didInstallPackagesWithResult:
- Callback associated withNMAMapLoader
installMapPackages:
method call -
mapLoader:didUninstallPackagesWithResult:
- Callback associated withNMAMapLoader
uninstallMapPackages:
method call -
mapLoader:didFindUpdate:fromVersion:toVersion:withResult:
- Callback associated withNMAMapLoader
checkForMapDataUpdate
method call -
mapLoader:didGetUpdateSize:withResult:
- Callback associated withNMAMapLoader
getMapDataUpdateSize
method call -
mapLoader:didUpdateWithResult:
- Callback associated withNMAMapLoader
performMapDataUpdate
method call -
mapLoader:didGetMapPackages:withResult:
- Callback associated withNMAMapLoader
getMapPackages
method call -
mapLoader:didGetMapPackage:atGeoCoordinates:withResult:
- Callback associated withNMAMapLoader getMapPackageAtGeoCoordinates:
method call -
mapLoaderDidLoseConnection:
- Callback sent when theNMAMapLoader
loses its server connection during an operation -
mapLoaderDidFindConnection:
- Callback sent when theNMAMapLoader
reestablishes its connection
NMAMapLoader
is downloading a map package, the download continues to run in the background for a maximum of three minutes. If the download was not completed within this time, then the download resumes when the app becomes active again. Map Loader Example on GitHub
You can find an example that demonstrates this feature at https://github.com/heremaps/ (Obj-C) and https://github.com/heremaps/ (Swift).
NMAMapLoaderResult Enum
NMAMapLoaderResult
is an enum data type representing the status for NMAMapLoader
operations. The status is returned through the NMAMapLoaderDelegate
protocol.
-
NMAMapLoaderResultSuccess
-NMAMapLoader
operation was completed without errors. -
NMAMapLoaderResultInvalidParameters
-NMAMapLoader
operation was called with invalid parameters. -
NMAMapLoaderResultOperationCancelled
-NMAMapLoader
operation was cancelled by a call to cancelCurrentOperation. -
NMAMapLoaderResultConnectionFailed
- a connection to the map data server cannot be made. -
NMAMapLoaderResultInitializationFailed
- theNMAMapLoader
could not be initialized.
It is recommended to check the network connectivity at the application level to ensure NMAMapLoader
operations are only performed when the device has a connection.
NMAMapPackage Interface
The map data packages available for download are represented as a tree structure with the root map package representing the world map. The NMAMapPackage
interface represents the model through which this tree structure is accessed. The properties of class NMAMapPackage
are:
parent
children
packageld
sizeOnDisk
installed
The installed
state of a particular NMAMapPackage
instance is not updated dynamically to reflect changes to map data on disk. For example, if you retrieve an NMAMapPackage
instance with getMapPackages
and then call installMapPackages
method with this package as the parameter, this package state remains the same even when didInstallPackagesWithResult
callback occurs. Instead, if you want to retrieve an NMAMapPackage
with the latest install state, access NMAMapLoader rootPackage
property. The rootPackage
property is updated with a new object instance after every install operation.
Incremental Updates
MapLoader exposes the ability to update the map data version to provide the user with the freshest map data available. The map data version applies not only to map data pre-installed using the MapLoader but also to data downloaded on-demand.
Map data version is consistent for all map data across the entire system, whether the map data is downloaded or not. It is not possible to have some data from one map version and other data from another map version concurrent in the disk cache. Therefore, it is important to keep the map version of the system up to date.
You can perform incremental updates if you are updating to the latest map data release from the two previous releases. Incremental updates are typically small downloads as only the changes are downloaded. For example, when updating to the Q1 2018 map data release from the Q4 2017 or Q3 2017 release, an incremental update or patch is used. Where a patch is not available (such as updating from Q2 2017 to Q1 2018), all map data packages are re-downloaded resulting in a much larger download size. Map version updating is exposed through checkForMapDataUpdate
and performMapDataUpdate
methods of NMAMapLoader
.
Data Groups
Map packages are made of several groups each of which contains a different type of map data. Some of these groups may be selected or deselected before map packages are downloaded for offline use depending on the needs of the application. The optional data groups are given in NMAMapDataGroup
enum. To select or deselect a data group for download, pass the appropriate enum value to NMAMapLoader selectDataGroup:
or deselectDataGroup:
method. isDataGroupSelected:
method can be used to query the current selection state of a data group.
The selected data groups of map loader are used for all future installation operations. However, changes to the data group selection do not affect previously installed packages. To update these packages, call performMapDataUpdate
after changing the data group selection.
NMAMapDataGroupTruckAttributes
or NMAMapDataGroupScooterAttributes
can be excluded if app only supports car.