On this page, find instructions on how to build and run the read example project on different platforms and get catalog and partition metadata, as well as partition data using HERE Data SDK for C++.
Before you run the example project, authorize to the HERE platform:
-
On the Apps & keys page, copy your application access key ID and access key secret.
For instructions on how to get the access key ID and access key secret, see Register your application section in the Identity & Access Management Developer Guide.
-
In
examples/main.cpp, replace the placeholders with your access key ID, access key secret, and Here Resource Name (HRN) of the catalog.You can also specify these values using the command line options.
AccessKey access_key{}; // Your access key ID and access key secret.
To build and run the example project on Linux:
-
Enable examples of the CMake targets.
mkdir build && cd build cmake -DOLP_SDK_BUILD_EXAMPLES=ON ..
-
In the build folder, build the example project.
cmake --build . --target dataservice-example -
Execute the example project.
./examples/dataservice-example --example read --key_id "here.access.key.id" --key_secret "here.access.key.secret" --catalog "catalog"
-
(Optional) To run the example with other parameters, run the help command, and then select the needed parameter.
./examples/dataservice-example --help
After building and running the example project, you see the following information:
edge-example-catalog– a catalog description.versioned-world-layer– a layer description.Request partition data - Success, data size - 3375– a success message that displays the size of data retrieved from the requested partition.
[INFO] read-example - Catalog description: edge-example-catalog
[INFO] read-example - Layer 'versioned-world-layer' (versioned): versioned-world-layer
[INFO] read-example - Layer contains 1 partitions
[INFO] read-example - Partition: 1
[INFO] read-example - Request partition data - Success, data size - 3375To integrate the Data SDK libraries in the Android example project:
- Set up the Android environment.
- In
examples/android/app/src/main/cpp/MainActivityNative.cpp.in, replace the placeholders with your application access key ID, access key secret, and catalog HRN and specify that the example should runRunExampleRead.
To learn how to get the access key ID and access key secret, see the Register your application section in the Identity & Access Management Developer Guide.
-
Set
OLP_SDK_BUILD_EXAMPLEStoON. -
(Optional) To disable tests, set
OLP_SDK_ENABLE_TESTINGtoOFF. -
Specify the path to the Android NDK toolchain file using the
CMAKE_TOOLCHAIN_FILEvariable. -
If you want to build the SDK for a specific Android platform, use the
-DANDROID_PLATFORM CMakeflag, and if you want to build the SDK for a specific Android architecture, use the-DANDROID_ABIflag. For more details, see NDK-specific CMake variables.mkdir build && cd build cmake .. -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DOLP_SDK_BUILD_EXAMPLES=ON -DOLP_SDK_ENABLE_TESTING=OFF
The CMake command generates a
Gradleproject in thebuild/examples/androidfolder. -
Install the Data SDK libraries into the sysroot directory.
# If necessary, execute as sudo. (sudo) make install
- In the Android Studio IDE, open the
build/examples/android/build.gradlescript. - Provide your application access key ID, access key secret, and catalog HRN.
- Install and run the
dataservice_exampleAPK.
The main screen displays the following message: "Example has finished successfully".
To integrate the Data SDK libraries in the iOS example project written in the Objective-C language:
-
To set up the iOS development environment, install the Xcode and command-line tools.
-
Install external dependencies.
For information on dependencies and installation instructions, see the related section in the README.md file.
-
In
examples/ios/ViewController.mm, replace the placeholders with your application access key ID, access key secret, and catalog HRN and specify that the example should runRunExampleRead.
To learn how to get the access key ID and access key secret, see the Register your application section in the Identity & Access Management Developer Guide.
-
Set
OLP_SDK_BUILD_EXAMPLEStoON. -
(Optional) To disable tests, set
OLP_SDK_ENABLE_TESTINGtoOFF. -
Specify the path to the iOS toolchain file using the
CMAKE_TOOLCHAIN_FILEvariable.The iOS toolchain file is shipped together with the SDK and located under the
<olp-sdk-root>/cmake/toolchains/iOS.cmake.
mkdir build && cd build
cmake .. -GXcode -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/iOS.cmake -DPLATFORM=iphoneos -DOLP_SDK_BUILD_EXAMPLES=ON -DOLP_SDK_ENABLE_TESTING=OFFTo configure Data SDK for a simulator, set the SIMULATOR CMake variable to ON.
-
Open the generated Xcode project.
open olp-cpp-sdk.xcodeproj
-
In the Xcode project, from the list of schemes, select the
dataservice-examplescheme. -
In the
dataservice-exampletarget, specify your application access key ID and access key secret. -
Build and run the example application.
The main UI screen displays the following message: "Reading the partition data from the specified catalog completed successfully". For more details, check the device logs.
If you encounter an error message, for a detailed error description, check the device logs. Example of an error message: "Failed to read data from the specified catalog!"
Catalog metadata contains a list of configurations that describe the catalog and its layers. Configuration information about the catalog includes the following metadata:
- Name
- HERE Resource Name (HRN)
- Description
- Owner
- Version
- Layer information
To get catalog metadata:
-
Create the
OlpClientSettingsobject.For instructions, see Create platform client settings.
-
Create the
CatalogClientobject with the catalog HRN and platform client settings from step 1.olp::dataservice::read::CatalogClient catalog_client( olp::client::HRN(kCatalogHRN), client_settings);
-
Create the
CatalogRequestobject.auto request = olp::dataservice::read::CatalogRequest(); -
(Optional) Set the needed parameters. For example, to set the billing tag, set the
WithBillingTagparameter.request.WithBillingTag("MyBillingTag"); -
Call the
GetRequestmethod with theCatalogRequestparameter.auto future = catalog_client.GetCatalog(request); -
Wait for
CatalogResponsefuture.olp::dataservice::read::CatalogResponse catalog_response = future.GetFuture().get();
The CatalogResponse object holds details of the completed operation and is used to determine operation success and access resultant data:
IsSuccessful()– if the operation is successful, returnstrue. Otherwise, returnsfalse.GetResult()– if the operation is successful, returns the following resultant data:olp::dataservice::read::CatalogResultGetError()– contains error information as a result of an error in theolp::client::ApiErrorobject.
if (catalog_response.IsSuccessful()) {
const auto& response_result = catalog_response.GetResult();
// Handle success
} else {
auto api_error = catalog_response.GetError();
// Handle fail
}The CatalogResult class contains the following methods used to get details of the relevant catalog:
GetId– returns the catalog ID.GetHrn– returns the catalogHRN.GetName– returns the catalog name.GetSummary– returns the summary description of the catalog.GetDescription– returns the full description of the catalog.GetCoverage– returns the coverage area of the catalog.GetOwner– returns the identity of the catalog owner.GetTags– returns the catalog tags collection.GetBillingTags– returns the billing tags set on the catalog.GetCreated– returns the catalog creation time.GetLayers– returns details of the layers contained in the catalog.GetVersion– returns the current catalog version number.GetNotifications– returns the catalog notification status.
The ApiError class contains the following methods used to get details of the incurred error:
GetErrorCode– returns theErrorCodevalue defined by theolp::client::ErrorCode enum. For more details, seeErrorCode.h.GetHttpStatusCode– returns the HTTP response code.GetMessage– returns a text description of the encountered error.ShouldRetry– returnstrueif this operation can be retried.
Partition metadata consists of the following information about the partition:
- Data handle
- ID
- Version
- Data size
- Compressed data size
- Checksum
To get partition metadata:
-
Create the
OlpClientSettingsobject.For instructions, see Create platform client settings.
-
Depending on the layer type, create a versioned or volatile layer client with the HERE Resource Name (HRN), layer ID, layer version, and platform client settings from step 1.
If you do not specify a catalog version, the latest version is used. Depending on the fetch option that you specified in your first API call to the client, the
GetLatestVersionmethod automatically gets the latest version in one of the following ways:- For the
OnlineIfNotFoundfetch option, queries the network, and if an error occurs, checks the cache. If the online version is higher than the cache version, the cache version is updated. - For the
OnlineOnlyfetch option, only queries the network. - For the
CacheOnlyfetch option, only checks the cache.
olp::dataservice::read::VersionedLayerClient layer_client( olp::client::HRN(kCatalogHRN), layer_id, version, client_settings);
- For the
-
Create the
PartitionsRequestobject with one of the following fetch options:- (Default) To query network if the requested resource is not found in the cache, use
OnlineIfNotFound. - To skip cache lookups and query the network right away, use
OnlineOnly. - To return immediately if a cache lookup fails, use
CacheOnly. - (Not for
VersionedLayerClient) To return the requested cached resource if it is found and update the cache in the background, useCacheWithUpdate.
auto request = olp::dataservice::read::PartitionsRequest() .WithBillingTag("MyBillingTag") .WithFetchOption( olp::dataservice::read::FetchOptions::OnlineIfNotFound);
- (Default) To query network if the requested resource is not found in the cache, use
-
Call
GetPartitionsmethod with thePartitionRequestparameter.auto future = layer_client.GetPartitions(request);If your layer uses tile keys as partition IDs, this operation can fail because of the large amount of data.
-
Wait for the
PartitionsResponsefuture.olp::dataservice::read::PartitionsResponse partitions_response = future.GetFuture().get();
The PartitionsResponse object holds the details of the completed operation and is used to determine operation success and access resultant data:
IsSuccessful()– if the operation is successful, returnstrue. Otherwise, returnsfalse.GetResult()– if the operation is successful, returns the following resultant data:olp::dataservice::read::PartitionsResultGetError()– contains error information as a result of an error in theolp::client::ApiErrorobject.
if (partitions_response.IsSuccessful()) {
const olp::dataservice::read::PartitionsResult& response_result =
partitions_response.GetResult();
// Handle success
} else {
// Handle fail
}The PartitionsResult class contains the GetPartitions method that returns a collection of partition metadata objects of the olp::dataservice::read::model::Partition type.
The Partition class contains partition metadata and exposes the following members:
GetChecksum– returns partition checksum.GetCompressedDataSize– returns the size of the compressed partition data.GetDataHandle– returns the handle that can be used by theGetDatafunction to retrieve the partition data.GetDataSize– returns the size of the partition data.GetPartition– returns the partition ID.GetVersion– returns the latest catalog version for the partition.
You can request any data version from a versioned layer. When you request a particular version of data from the versioned layer, the partition you receive in the response may have a lower version number than you requested. The version of a layer or partition represents the catalog version in which the layer or partition was last updated.
To get data from the versioned layer:
-
Create the
OlpClientSettingsobject.For instructions, see Create platform client settings.
-
Create the
VersionedLayerClientobject with the HERE Resource Name (HRN) of the catalog that contains the layer, the layer ID, catalog version, and the platform client settings from step 1.If you do not specify a catalog version, the latest version is used. Depending on the fetch option that you specified in your first API call to the client, the
GetLatestVersionmethod automatically gets the latest version in one of the following ways:- For the
OnlineIfNotFoundfetch option, queries the network, and if an error occurs, checks the cache. If the online version is higher than the cache version, the cache version is updated. - For the
OnlineOnlyfetch option, only queries the network. - For the
CacheOnlyfetch option, only checks the cache.
olp::dataservice::read::VersionedLayerClient layer_client ( client::HRN catalog, std::string layer_id, porting::optional<int64_t> catalog_version, client::OlpClientSettings settings);
- For the
-
Create the
DataRequestobject with the partition ID and one of the following fetch options:- (Default) To query the network if the requested resource is not found in the cache, use
OnlineIfNotFound. - To skip cache lookups and query the network right away, use
OnlineOnly. - To return immediately if a cache lookup fails, use
CacheOnly.
auto request = olp::dataservice::read::DataRequest() .WithPartitionId(partition_id) .WithBillingTag("MyBillingTag") .WithFetchOption(olp::dataservice::read::FetchOptions::OnlineIfNotFound);
- (Default) To query the network if the requested resource is not found in the cache, use
-
Call the
GetRequestmethod with theDataRequestparameter.auto future = layer_client.GetData(request); -
Wait for the
DataResponsefuture.olp::dataservice::read::DataResponse data_response = future.GetFuture().get();
The DataResponse object holds details of the completed operation and is used to determine operation success and access resultant data:
IsSuccessful()– if the operation is successful, returnstrue. Otherwise, returnsfalse.GetResult()– if the operation is successful, returns the following resultant data:olp::dataservice::read::DataResultGetError()– contains error information as a result of an error in theolp::client::ApiErrorobject.
if (data_response.IsSuccessful()) {
const auto& response_result = data_response.GetResult();
// Handle success
} else {
auto api_error = data_response.GetError();
// Handle fail
}The DataResult class contains raw partition data that is an alias for a std::shared_ptr<std::vector<unsigned char>>.