HERE Android SDK Developer's Guide

Using CLE2 Offline

The same search requests that were possible via the server are also available offline. This CLE2 feature allows your app to pre-fetch full data layers from the server, or only cache objects returning from specific geospatial requests during runtime. This enables more efficient use of network resources, since your app can only cache and update data that is near the user's current location, or pre-download a whole layer only when a WiFi network becomes available. Also, because the data is local to the device, the application can become more responsive in offline mode, thus improving the user experience and user interface interactions.

The Offline CLE2 features are designed to be simple to use. This is so that all database synchronization and geospatial-related complexities are handled by the SDK, and you can focus on other parts of app development.

Populating the Local Storage

By default, offline features are disabled and the local storage contains no data. There are currently two ways to add geometries to make them available for offline searches:

  1. Enable caching when performing one or more requests, such as CLE2ProximityRequest. Note that you cannot cache attribute requests.
  2. Download one or more layers.

When caching is enabled in an CLE2Request, any returned geometries are automatically stored locally. To activate it, call setCachingEnabled(true) before performing the request:

// set query
String query = "CITY=='Berlin'";
request.setQuery(query);

// set Geometry type
request.setGeometry(CLE2GeometryType.LOCAL);

// to cache response
request.setCachingEnabled(true);

The second option is to use CLE2DataManager to insert data to the local storage using the downloadLayer(String, CLE2DownloadListener) method. CLE2DataManager is the central interaction point with the local storage is the object. With it, it is possible to:

  • Download a complete layer and all geometries in it from the server.
  • Check how many geometries are currently stored in total or in a specific layer.
  • Delete geometries belonging to a specific layer.
  • Purge the local storage.

The following is an example of how to use the downloadLayer(String, CLE2DownloadListener) method:

CLE2DataManager manager = CLE2DataManager.getInstance();
manager.downloadLayer("HERE_TEST", new CLE2DownloadListener() {
     @Override
    public void onLayerDownloaded(String layerName, CLE2Error error) {
       String message = "";
       if (error.getErrorCode() == CLE2ErrorCode.NONE) {
       message = "Successfully downloaded layer " + layerName;
       } else {
       message = error.getErrorMessage();
       }
       Toast.makeText(CLE2Activity.this, message, Toast.LENGTH_LONG).show();
    }
 });

// clear all
CLE2DataManager manager = CLE2DataManager.getInstance();
if (manager.deleteAll()) {
  Toast.makeText(CLE2Activity.this, "Cache cleared successfully", Toast.LENGTH_LONG).show();
}
Note: Since downloaded layers are not automatically updated when server data is updated, you need to download updates by calling downloadLayer(String, CLE2DownloadListener) with the same layer ID again. When you call this method, it first checks if data updates are available, and then it downloads the data if it finds an update. Data updates are always performed through full layer downloads. Incremental downloads are not yet supported.

Automatic Mode

It is also possible to configure the search request to a "hybrid/automatic" mode, meaning that if during an online request the connection drops or there's a network error, the request will fall back to an offline operation automatically:

request.setRequestMode(type);

// eg. set offline mode
request.setRequestMode(CLE2RequestMode.AUTO);

You cannot use this account to purchase a commercial plan on Developer Portal, as it is already associated to plans with different payment methods.

To purchase a commercial plan on Developer Portal, please register for or sign in with a different HERE Account.

Something took longer than expected.

The project should be available soon under your projects page.

Sorry, our services are not available in this region.

Something seems to have gone wrong. Please try again later.

We've detected that your account is set to Australian Dollars (AUD).
Unfortunately, we do not offer checkouts in AUD anymore.
You can continue using your current plan as normal, but to subscribe to one of our new plans,
please register for a new HERE account or contact us for billing questions on selfservesupport@here.com.