Recommend Offline Region

This guide covers how to help users choose the right offline regions by recommending regions near the current position or along a route, then display region boundaries on the map before download.

Recommend Regions by Current Position or Route

1
val radiusTask = NBNavigation.getCountiesInRadius(
2
latitude,
3
longitude,
4
50_000.0,
5
regionListCallback
6
)
7
8
val routeTask = NBNavigation.getCountiesAlongRoute(
9
directionsRoute,
10
regionListCallback
11
)

These two APIs return recommended regions only and they do not start downloads. Call cancel() on the task when its result is no longer needed or when the screen is destroyed. The radius must be a finite, non-negative value in meters, and the route must contain at least two valid geometry points.

Display Region Boundaries

1
NBNavigation.getRegionBoundary(
2
regionId,
3
object : NBNavigationTaskCallback<OfflineRegionBoundary> {
4
override fun onSuccess(result: OfflineRegionBoundary?) {
5
result?.geoJson?.takeIf { it.isNotBlank() }?.let {
6
updateSelectedRegionGeoJsonSource(it)
7
zoomToRegionBoundary(it)
8
}
9
}
10
11
override fun onError(throwable: Throwable) {
12
showOfflineError("Loading region boundary failed", throwable)
13
}
14
}
15
)

When boundary details are missing locally, the default overload may access the network. For a local-only batch read, use getRegionBoundary(longArrayOf(...), false, callback). Retrieve all installed road-network boundaries with getInstalledRoutesRegionBoundaryFeatureCollection() and pass the result directly to a map GeoJSON Source.

The Maps SDK manages installed map databases automatically through the normal MapView lifecycle and the application does not need to register database paths manually.

To move the map camera to an installed region, call focusMapTilePreviewRegion(nextbillionMap, regionId) on the main thread and check its return value.