Offline
There are two main kinds of offline functionality: predictive caching and offline regions. Predictive caching is fully automatic and based on the driver’s behavior. It allows offline navigation around the user’s current location, the destination, and the route itself. Offline regions need to be created and loaded ahead of time, enabling routing functionality in non-connected environments.
Predictive caching
To use predictive caching, you will need to initialize a PredictiveCacheController
and, optionally, configure a radius and cache size. Once these items are configured, the Navigation SDK will automatically create caches and make them available to the user.
To start caching map data, call createMapControllers
with a MapboxMap
instance and, optionally, pass a list of source IDs to specify sources to cache. Sources must be hosted on Mapbox, and the source ID must start with “mapbox://”
(for example, “mapbox://mapbox.mapbox-terrain-v2”
). If you do not pass any IDs to createMapControllers
, all available style sources will be cached by default. There can be multiple instances of the map caching resources at a time.
predictiveCacheController = new PredictiveCacheController(predictiveCacheLocationOptions, predictiveCacheControllerErrorHandler);
<String> sourceIdsToCache = new ArrayList<>();
sourceIdsToCache.add("mapbox://mapbox.mapbox-terrain-v2");
// cache only passed sources for the mapboxMap instance
predictiveCacheController.createMapControllers(mapboxMap, sourceIdsToCache);
// cache all sources for the anotherMapboxMap instance
predictiveCacheController.createMapControllers(anotherMapboxMap);
predictiveCacheController = PredictiveCacheController(predictiveCacheLocationOptions, predictiveCacheControllerErrorHandler)
// cache only passed sources for the mapboxMap instance
predictiveCacheController.createMapControllers(mapboxMap, listOf("mapbox://mapbox.mapbox-terrain-v2"));
// cache all sources for the anotherMapboxMap instance
predictiveCacheController.createMapControllers(anotherMapboxMap);