On this page
Download map tiles within a polygonal area - Swift SDK
The MapTiler SDK for iOS provides a powerful Offline Pack API that allows you to download tiles within a polygonal area defined by a GeoJSON Polygon 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 Polygon (GeoJSON Polygon)
import MapTilerSDK
// Your GeoJSON Polygon
let polygonGeoJSON = """
{
"type": "Polygon",
"coordinates": [[
[8.5417, 47.3769],
[8.5457, 47.3769],
[8.5457, 47.3799],
[8.5417, 47.3799],
[8.5417, 47.3769]
]]
}
"""
Task {
do {
// Extract coordinates from GeoJSON
let polyCoords = try MTGeoJSONParser.extractCoordinates(from: polygonGeoJSON)
// Create the polygon definition
let polyDefinition = MTOfflineRegionDefinition(
geometry: .polygon(polyCoords),
minZoom: 1,
maxZoom: 12,
referenceStyle: .streets
)
// Create and download the pack
let pack = try await MTOfflinePack.createPack(region: polyDefinition)
await pack.download()
print("Polygon download started")
} catch {
print("Error: \(error)")
}
}
Learn more
For more information browse our API Reference
Check out our SDK Swift Examples.
Was this helpful?