Download map tiles along a specific route - Kotlin SDK

The MapTiler SDK for Kotlin provides a powerful Offline Pack API that allows you to download map tiles along a specific route defined by a GeoJSON LineString 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.

Offline Pack for a Route (GeoJSON LineString)


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

// Your GeoJSON LineString
val routeGeoJson = """
{
    "type": "LineString",
    "coordinates": [
        [8.5417, 47.3769],
        [8.5427, 47.3779],
        [8.5437, 47.3789]
    ]
}
"""

MainScope().launch {
    try {
        // Parse the route geometry from GeoJSON
        val geometry = MTOfflineRegionGeometry.Route.fromGeoJson(routeGeoJson)

        // Create the route definition with 1000m padding
        val routeDefinition = MTOfflineRegionDefinition(
            geometry = geometry,
            minZoom = 0,
            maxZoom = 14,
            referenceStyle = MTMapReferenceStyle.STREETS,
            padding = 1000.0
        )

        // Create and download the pack
        val pack = MTOfflineManager.createPack(context, routeDefinition)
        pack.download()
        println("Route download started")
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

Learn more

For more information browse our API Reference

Check out our SDK Kotlin Examples.

Was this helpful?
Mobile SDK
Android
Download map tiles along a specific route - Kotlin SDK
Offline for a route