Simple Map (iOS)
Zeigt eine im SmartMaps-Stil gestaltete Karte in einer iOS-App mit MapLibre Native an.
MapSession erforderlich
Denken Sie daran, die MapSession in Ihre App zu integrieren. Die MapSession muss alle 10 Minuten aufgerufen werden, solange die Karte aktiv ist.
UIKit
import UIKit
import MapLibre
class MapViewController: UIViewController {
private var mapView: MLNMapView!
override func viewDidLoad() {
super.viewDidLoad()
let styleURL = URL(string:
"https://tiles.smartmaps.cloud/styles/v1/smartmaps/light/style.json?apiKey=[INSERT API-KEY]&channel=app"
)!
mapView = MLNMapView(frame: view.bounds, styleURL: styleURL)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.setCenter(
CLLocationCoordinate2D(latitude: 49.0069, longitude: 8.4037), // Karlsruhe
zoomLevel: 12,
animated: false
)
view.addSubview(mapView)
}
}
SwiftUI
import SwiftUI
import MapLibre
import MapLibreSwiftUI
struct SimpleMapView: View {
let styleURL = URL(string:
"https://tiles.smartmaps.cloud/styles/v1/smartmaps/light/style.json?apiKey=[INSERT API-KEY]&channel=app"
)!
var body: some View {
MapView(styleURL: styleURL)
.initialViewport(
.centerAndZoom(
center: CLLocationCoordinate2D(
latitude: 49.0069,
longitude: 8.4037
),
zoom: 12
)
)
}
}