On this page
Download map area by defining its bounding box - Kotlin SDK
The MapTiler SDK for Kotlin provides a powerful Offline Pack API that allows you to download a rectangular area by defining its bounding box for use without an active internet connection.
Before you begin, ensure you have followed the Android getting started with offline pack API to set up your project and obtain your API key.
Basic Offline Pack (Bounding Box)
import com.maptiler.maptilersdk.offline.MTBoundingBox
import com.maptiler.maptilersdk.offline.MTOfflineManager
import com.maptiler.maptilersdk.offline.MTOfflineRegionDefinition
import com.maptiler.maptilersdk.offline.MTOfflineRegionGeometry
import com.maptiler.maptilersdk.map.style.MTMapReferenceStyle
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
// Define the bounding box
val bounds = MTBoundingBox(
minLon = 8.5170,
minLat = 47.3500,
maxLon = 8.5670,
maxLat = 47.4000
)
// Create the region definition
val definition = MTOfflineRegionDefinition(
geometry = MTOfflineRegionGeometry.BoundingBox(bounds),
minZoom = 1,
maxZoom = 12,
referenceStyle = MTMapReferenceStyle.STREETS
)
// Create and download the pack
MainScope().launch {
try {
val pack = MTOfflineManager.createPack(context, definition)
pack.download()
println("Download started for pack: ${pack.id}")
} catch (e: Exception) {
e.printStackTrace()
}
}
Learn more
For more information browse our API Reference
Check out our SDK Kotlin Examples.
Was this helpful?