How to use OCM packager tool with HERE Mobile SDK

OCM-MAP Packager User Guide

Please Note: This guide is for Ubuntu Linux, as for Windows there is a direct package that can be used with EXE file.

# OCM Packager

OCM packager is a console tool, which allows preparing map packages for offline usage.

## Linux dependencies

External libraries are needed to run the ocm-packager on Linux.

To install the dependencies on Ubuntu Linux, run the following command:

For Ubuntu

```

sudo apt-get update && sudo apt-get --yes install libssl-dev libcurl4-openssl-dev libboost-all-dev

```

For CentOS 8 Stream

```

sudo yum install dnf

sudo dnf install -y git epel-release
sudo yum install boost-devel
sudo yum install libcurl-devel.x86_64
sudo yum install openssl-devel


```

For Ubuntu and CentOS 8 stream: Please download the file from this link and extract the same.

For Windows: Please download the file from this link and extract the same.


Once downloaded and extracted, please run command - sudo su, this will give you root access.

In the root of the folder you will find following files:**Graphical user interface, applicationDescription automatically generated


You need to create a .JSON file which will include the schema to download offline map package based on region, for downloading Berlin region package, please see the sample .JSON file -

{
  "storage": "protectedCache",
  "mapPackage": {
    "catalogs": [
      {
        "hrn": "hrn:here:data::olp-here:ocm"
      }
    ],
    "layerGroups": ["routing", "rendering", "detailed_rendering", "navigation", "interop", "pedestrian_offline_routing", "truck", "traffic", "landmarks", "search", "index", "configuration", "car_offline_routing", "truck_offline_routing", "long_truck_offline_routing", "traffic_patterns"],
    "regionList": [20187401]
  }
}



Save the above file with name “berlin.json” and put it in the root of the folder.

Please download the detailed regionList from this link

To prepare map package, use the following execution parameters:

| Parameter| Description| Note|

|-------------------|-----------|------------|

| --credentials PATH| Read credentials from the provided file. If the credentials file located in the HOME directory inside .here folder, this option can be omitted.| For more details, refer to Get Credentials.|

| --configuration PATH| Read configuration of required package from the provided file.| -|

| -o [ --output-path ] PATH| The PATH to the folder to save map data or zip archive to.| -|

| -z [ --zip-filename ] ZIP_FILENAME| Archive the loaded data to ZIP_FILENAME.| The data will not be archived if this parameter is not set.|

| -p [ --print-regions ]| Print a list of regions for specified catalog and exit successfully.| Catalog HRN is required for this operation.|

| -c [ --catalog-hrn ] HRN| HERE Resource Name of the catalog to download the regions list from.| -|

| --catalog-version VERSION| The version of the catalog to download the regions list from.| The latest version is used if not provided.|

| -l [ --log-level ] LEVEL| The log level to be used during execution.| Available levels are: Trace, Debug, Info, Warning, Error, Fatal, Off. The default value is Info.|

| -h [ --help ]| Print the help and exit successfully.| -|

| -v [ --version ]| Print version of the OCM packager and exit successfully.| -|

The next step is to create and download “credential.properties” file, which you can download from – https://platform.here.com after logging-in with your realm.

Follow simple steps:

1) Register any app.


2) Link the app to the OCM catalog.

3) Generate OATH credentials.
4) Download the credential.properties file.


Once you have both the “. JSON and credential.properties” file, put both the files in the root of OCM packager extracted folder. The final hierarchy would look like the following -**Graphical user interface, applicationDescription automatically generated

*Once the hierarchy is ready, please run the following command as root -
./bin/ocm-packager --credentials ./credentials.properties --configuration berlin.json -o pm -z berlin.zip*



*Please Note: You need to give permission chmod 777 to ./bin/ocm-packager

The above command will create berlin.zip package map in folder pm*

Once this package is created you need to unzip and copy the contents to the place you need to deploy the same.**Graphical user interfaceDescription automatically generated

Create the folder structure like - /berlin/v1/com.here.sdk.access_key_id/ocm-map/ and copy the above files in ocm-map folder**.

How to use the above created folder structure from HERE SDK 4.x

Navigate SDK

The above created path that is used by the HERE SDK to access the persistent map storage (pre-installed maps) can be configured either at runtime or through the AndroidManifest. See also here: https://www.here.com/docs/bundle/sdk-for-android-developer-guide/page/topics/offline-maps-installation.html

The default locations are also documented in above link.

### Notes

If persistentMapStoragePath is not set, the SDK falls back to internal app storage.
The directory must be valid and writable. If you point to a read-only location, you’ll need to configure dataPath instead.Always keep this under an app-specific directory (like /Android/data//files/) rather than shared folders such as Documents to avoid exposing SDK files to other apps.
Changing the path after the engine is running is not supported - you must configure it when creating a new SDKNativeEngine.

In addition to above you need to define following permission in Android.manifest file, if you are trying to store the map package in external storage:*

persistentMapStoragePath

android:name="android.permission.WRITE_EXTERNAL_STORAGE" />android:name**="android.permission.READ_EXTERNAL_STORAGE" />

@NonNull

public java.lang.String persistentMapStoragePath

Path to store persistent map data. This should be the absolute path to the desired location for which the application has read/write permissions. The path can be on internal or external storage. If it is not set, the default path will be used and the default path is Context.getFilesDir().getPath(), if the SDK is initialized with manifest. If the HERE SDK is initialized explicitly

and InitProvider is deactivated, then the path is empty until an instance
of SDKNativeEngine is created at least once
with
SDKNativeEngine(android.content.Context,
SDKOptions)
or SDKNativeEngine.makeSharedInstance(android.content.Cont ext, com.here.sdk.core.engine.SDKOptions)**. If path is relative then directoryContext.getFilesDir().getPath() is used as parent path.

*Note**: Offline maps stored
at /v1//ocm-map/,
where is taken either
from SDKOptions.accessKeyId or SDKOptions.authenticationMode (SDKOptio ns.accessKeyId has higher priority). When SDKOptions initialized*