Download map tiles along a specific route - Swift SDK

The MapTiler SDK for iOS 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 iOS Getting Started with Offline Pack API to set up your project and obtain your API key.

Offline Pack for a Route (GeoJSON LineString)


import MapTilerSDK

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

Task {
    do {
        // Extract coordinates from GeoJSON
        let coordinates = try MTGeoJSONParser.extractCoordinates(from: routeGeoJSON)
        
        // Create the route definition with 1000m padding
        let routeDefinition = MTOfflineRegionDefinition(
            geometry: .route(coordinates),
            minZoom: 1,
            maxZoom: 12,
            referenceStyle: .streets,
            padding: 1000
        )
        
        // Create and download the pack
        let pack = try await MTOfflinePack.createPack(region: routeDefinition)
        await pack.download()
        print("Route download started")
    } catch {
        print("Error: \(error)")
    }
}

Learn more

For more information browse our API Reference

Check out our SDK Swift Examples.

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