Add Pre-made controls to your map - Swift SDK

The term control is commonly used for all sorts of buttons and information display that take place in one of the corner of the map area. The most well know are probably the zoom in [+] and zoom out [-] buttons as well as the attribution information.

This example shows how to add controls during your map initialization and enable most common map interactions instantly.


import SwiftUI
import CoreLocation
import MapTilerSDK

struct ContentView: View {
  init() {
    // Best practice: set the MapTiler API key on app startup instead on init
    // Replace with your MapTiler API key
    Task { await MTConfig.shared.setAPIKey("MY_API_KEY") }
  }

  @State private var mapView = MTMapView(
    options: MTMapOptions(
      center: CLLocationCoordinate2D(latitude: 46.8, longitude: 8.33),
      zoom: 6,
      // Built-in controls
      terrainControlIsVisible: true,
      navigationControlIsVisible: true,
      geolocateControlIsVisible: true,
      projectionControlIsVisible: true,
      scaleControlIsVisible: true,
      minimapIsVisible: true,
      attributionControlIsVisible: true,
      // Logo toggle and position
      maptilerLogoIsVisible: true, // false works for premium accounts
      logoPosition: .topLeft
    )
  )

  var body: some View {
    MTMapViewContainer(map: mapView)
      .referenceStyle(.streets)
  }
}