Skip to main content

Show Map

Initializing the map SDK securely with an API key and rendering the base interactive map.


UIKit​

import SSMaplib

SSMap.setAPIKey(apiKey: "YOUR_MAP_KEY")

let mapView = SSMapView(frame: .zero)
mapView.setCenter(
CLLocationCoordinate2D(latitude: 28.6139, longitude: 77.2090),
zoomLevel: 12.0,
animated: false
)

SSMapView can be embedded directly in UIKit, or wrapped in UIViewRepresentable for SwiftUI.


SwiftUI integration​

MapViewRepresentable bridges the native SSMapView into SwiftUI using UIViewRepresentable, and also wires up map delegate callbacks (for example to set up shape layers once the style has loaded).

// Initialize inside the App lifecycle
SSMap.setAPIKey(apiKey: "YOUR_API_KEY_HERE")

// MapLibre UI wrapper
struct ContentView: View {
var body: some View {
MapViewRepresentable(viewModel: viewModel)
.edgesIgnoringSafeArea(.all)
}
}

// MapViewRepresentable implementation
// `UIViewRepresentable` is used here to bridge the native UIKit map (SSMapView) so it can be
// seamlessly embedded inside SwiftUI.
struct MapViewRepresentable: UIViewRepresentable {
@ObservedObject var viewModel: MapViewModel

func makeUIView(context: Context) -> SSMapView {
let mapView = SSMapView(frame: .zero)
viewModel.rawMapView = mapView
mapView.delegate = context.coordinator
mapView.setCenter(CLLocationCoordinate2D(latitude: 28.6139, longitude: 77.2090), zoomLevel: 12.0, animated: false)
mapView.compassView.isHidden = false

let longPress = UILongPressGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.handleLongPress(_:)))
mapView.addGestureRecognizer(longPress)

return mapView
}

func updateUIView(_ uiView: SSMapView, context: Context) {}

func makeCoordinator() -> Coordinator {
Coordinator(self)
}

class Coordinator: NSObject, MLNMapViewDelegate {
var parent: MapViewRepresentable
init(_ parent: MapViewRepresentable) { self.parent = parent }
func mapView(_ mapView: MLNMapView, didFinishLoading style: MLNStyle) {
parent.viewModel.setupLayers(style: style)
}
}
}

See also: Get Started, iOS Map SDK overview.