
Mapbox Ios Patterns
Drop Mapbox Maps SDK v11 patterns into an iOS app when you need SwiftUI, UIKit, annotations, and token setup without digging through docs.
Overview
mapbox-ios-patterns is an agent skill for the Build phase that supplies Mapbox Maps SDK v11 Swift, SwiftUI, and UIKit quick-reference snippets for tokens, maps, and annotations.
Install
npx skills add https://github.com/mapbox/mapbox-agent-skills --skill mapbox-ios-patternsWhat is this skill?
- SPM install pin for mapbox-maps-ios 11.0.0+
- Info.plist MBXAccessToken setup pattern
- SwiftUI Map with bound Viewport and .mapStyle(.standard)
- PointAnnotation with one-call UIImage image registration
- UIKit MapView + MapInitOptions and CameraOptions baseline
- Mapbox Maps SDK v11.0.0+ via SPM
Adoption & trust: 673 installs on skills.sh; 64 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are building an iOS map screen and keep losing time jumping between Mapbox install docs, plist keys, and SwiftUI versus UIKit entry points.
Who is it for?
Indie iOS apps that need a standard Mapbox v11 map with annotations in SwiftUI or UIKit.
Skip if: Android or web Mapbox stacks, turn-by-turn navigation product design, or teams that already maintain an internal Mapbox wrapper.
When should I use this skill?
Implementing or debugging Mapbox map screens, tokens, or annotations on iOS with SDK v11.
What do I get? / Deliverables
Your agent outputs working v11 setup and starter map code you can paste into the app target and iterate on styles and data layers.
- SPM dependency snippet
- plist token entry
- starter Map or MapViewController code
Recommended Skills
Journey fit
How it compares
Use as a focused SDK cheat sheet instead of generic “build a map app” chat without version-specific v11 APIs.
Common Questions / FAQ
Who is mapbox-ios-patterns for?
Solo and indie iOS developers and agents embedding Mapbox Maps SDK v11 in SwiftUI or UIKit apps during active product build.
When should I use mapbox-ios-patterns?
During Build when you add SPM dependencies, configure MBXAccessToken, stand up a basic Map or MapViewController, or register marker images for PointAnnotation.
Is mapbox-ios-patterns safe to install?
Review the Security Audits panel on this Prism page before installing; treat Mapbox access tokens as secrets and never commit production keys.
SKILL.md
READMESKILL.md - Mapbox Ios Patterns
# Mapbox iOS Quick Reference Fast reference for Mapbox Maps SDK v11 on iOS with Swift, SwiftUI, and UIKit. ## Setup ### Installation (SPM) ```swift // File → Add Package Dependencies https://github.com/mapbox/mapbox-maps-ios.git // Version: 11.0.0+ ``` ### Access Token ```xml <!-- Info.plist --> <key>MBXAccessToken</key> <string>pk.your_token_here</string> ``` ## SwiftUI ### Basic Map ```swift import SwiftUI import MapboxMaps struct MapView: View { @State private var viewport: Viewport = .camera( center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194), zoom: 12 ) var body: some View { Map(viewport: $viewport) .mapStyle(.standard) } } ``` ### With Annotation ```swift Map(viewport: $viewport) { PointAnnotation(coordinate: CLLocationCoordinate2D( latitude: 37.7749, longitude: -122.4194 )) // Register and use the image in one call — raster UIImage only. .image(.init(image: UIImage(named: "marker")!, name: "marker")) } .mapStyle(.standard) ``` ## UIKit ### Basic Map ```swift import UIKit import MapboxMaps class MapViewController: UIViewController { private var mapView: MapView! override func viewDidLoad() { super.viewDidLoad() let options = MapInitOptions( cameraOptions: CameraOptions( center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194), zoom: 12 ) ) mapView = MapView(frame: view.bounds, mapInitOptions: options) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) mapView.mapboxMap.loadStyle(.standard) } } ``` ## Common Patterns ### 1. Add Markers Three options — pick the simplest: - `Marker` (SwiftUI, experimental SPI) — default pin, no image assets. - `PointAnnotation` (SwiftUI + UIKit) — custom image, scales to hundreds via the underlying symbol layer. - View annotations (SwiftUI + UIKit) — arbitrary native view at a coordinate. ```swift // Markers API — SwiftUI, simplest import SwiftUI @_spi(Experimental) import MapboxMaps Map { Marker(coordinate: coord).color(.red).text("Coffee") } // PointAnnotation — UIKit, custom image var manager = mapView.annotations.makePointAnnotationManager() var annotation = PointAnnotation(coordinate: coordinate) annotation.image = .init(image: UIImage(named: "marker")!, name: "marker") manager.annotations = [annotation] ``` ### 2. User Location with Camera Follow ```swift import Combine var cancelables = Set<AnyCancellable>() // Request permission (add to Info.plist) let locationManager = CLLocationManager() locationManager.requestWhenInUseAuthorization() // Show user location mapView.location.options.puckType = .puck2D() mapView.location.options.puckBearingEnabled = true // Follow user location mapView.location.onLocationChange.observe { [weak self] locations in guard let self = self, let location = locations.last else { return } self.mapView.camera.ease(to: CameraOptions( center: location.coordinate, zoom: 15, bearing: location.course >= 0 ? location.course : nil ), duration: 1.0) }.store(in: &cancelables) ``` ### 3. Add Custom Data (GeoJSON) ```swift var source = GeoJSONSource(id: "route-source") source.data = .geometry(.lineString(LineString(coordinates))) try? mapView.mapboxMap.addSource(source) var layer = LineLayer(id: "route-layer", source: "route-source") layer.lineColor = .constant(StyleColor(.blue)) layer.lineWidth = .constant(4) try? mapView.mapboxMap.addLayer(layer) ``` ### 4. Camera Control ```swift // Fly animation mapView.camera.fly(to: CameraOptions( center: CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060), zoom: 14 ), duration: 2.0) // Ease animation mapView.camera.ease(to: CameraOptions( center: coordinate, zoom: 15 ), duration: 1.0) ``` ### 5. Featureset Interactions ```swift // Tap on POI featu