All skills
mapbox avatar

/mapbox-ios-patterns

@f5ae7de official
by mapboxmapbox/mapbox-agent-skills80 stars
17

Official integration patterns for Mapbox Maps SDK on iOS. Covers installation, adding markers, user location, custom data, styles, camera control, and featureset interactions. Based on official Mapbox documentation.

Use this Skill: https://skilld.dev/gh/mapbox/mapbox-agent-skills/mapbox-ios-patterns

This session only. Nothing lands on disk.

referencesannotations.md

≈790 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Annotations: Markers, Points, Circle, Polyline, Polygon

Deeper reference for the annotation APIs summarized in SKILL.md.


Picking an annotation API

  • Marker (Markers API) — SwiftUI-only convenience pin. No image assets required. Marked @_spi(Experimental); import with @_spi(Experimental) import MapboxMaps. Best when you just need a pin and have < 100 points.
  • PointAnnotation — SwiftUI + UIKit. Use when you have a custom image. Backed by a symbol layer under the hood, so it scales better than view annotations.
  • View annotations (ViewAnnotation / MapViewAnnotation) — SwiftUI + UIKit. Render an arbitrary native view anchored to a coordinate. In SwiftUI use MapViewAnnotation { SomeView() }; in UIKit use mapView.viewAnnotations.add(_:) with a ViewAnnotation. Expensive per annotation.
  • SymbolLayer on GeoJSONSource — for thousands of features, clustering, or data-driven styling.

Markers API (SwiftUI)

import SwiftUI
@_spi(Experimental) import MapboxMaps

struct MyMap: View {
    let locations: [Location]

    var body: some View {
        Map {
            ForEvery(locations, id: \.id) { location in
                Marker(coordinate: location.coordinate)
                    .color(.red)
                    .stroke(.white)
                    .innerColor(.white)
                    .text(location.name)
                    .onTapGesture {
                        print("tapped \(location.name)")
                    }
            }
        }
    }
}

Remove a marker by taking it out of the Map block — if / switch inside the builder work as expected.

Markers appear above all other map content (layers, annotations, puck). If you need layer-ordered placement, use PointAnnotation.

Point Annotations: custom image

var manager = mapView.annotations.makePointAnnotationManager()

var annotation = PointAnnotation(coordinate: coordinate)
annotation.image = .init(image: UIImage(named: "marker")!, name: "marker")
annotation.iconAnchor = .bottom

manager.annotations = [annotation]

Circle Annotations

var circleAnnotationManager = mapView.annotations.makeCircleAnnotationManager()

var circle = CircleAnnotation(coordinate: coordinate)
circle.circleRadius = 10
circle.circleColor = StyleColor(.red)

circleAnnotationManager.annotations = [circle]

Polyline Annotations

var polylineAnnotationManager = mapView.annotations.makePolylineAnnotationManager()

let coordinates = [coord1, coord2, coord3]
var polyline = PolylineAnnotation(lineCoordinates: coordinates)
polyline.lineColor = StyleColor(.blue)
polyline.lineWidth = 4

polylineAnnotationManager.annotations = [polyline]

Polygon Annotations

var polygonAnnotationManager = mapView.annotations.makePolygonAnnotationManager()

let coordinates = [coord1, coord2, coord3, coord1] // Close the polygon
var polygon = PolygonAnnotation(polygon: .init(outerRing: .init(coordinates)))
polygon.fillColor = StyleColor(.blue.withAlphaComponent(0.5))
polygon.fillOutlineColor = StyleColor(.blue)

polygonAnnotationManager.annotations = [polygon]

Source: SKILL.md on GitHub

1 warning17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides official integration patterns for the Mapbox Maps SDK on iOS, including installation, markers, location tracking, and custom data. It follows standard iOS development practices and utilizes official Mapbox resources. No security issues or malicious behaviors were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    2/2 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f5ae7de. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 9 hours ago.

Activeupdated 2 months ago
  • mapbox
  • ios
  • swift
  • swiftui
  • uikit
  • maps
  • annotations
  • geojson
  • location-tracking
  • camera-control

README badge

README badge for mapbox/mapbox-agent-skills/mapbox-ios-patterns

Installs and configures Mapbox Maps SDK v11 on iOS with Swift and SwiftUI, covering markers, user location, custom data layers, camera control, and feature interactions. Targets both SwiftUI and UIKit workflows and includes performance guidance for annotation management and style optimization.

Generated from the current SKILL.md.

Does this skill work with both SwiftUI and UIKit?
Yes. The skill covers both frameworks. Some APIs like `Marker` are SwiftUI-only, while `PointAnnotation` and `ViewAnnotation` work in both SwiftUI and UIKit.
What iOS version is required?
iOS 14 or later, with Xcode 15+ and Swift 5.9+. Mapbox Maps SDK v11 is the target version.
How do I handle hundreds or thousands of markers?
Use a `GeoJSONSource` with a `SymbolLayer` instead of individual annotations. The Markers and PointAnnotation APIs scale to about 100 markers; for larger datasets, load GeoJSON directly into a style layer, which scales to thousands of features and supports clustering.
Do I need a paid Mapbox account?
No. A free Mapbox account is sufficient to get an access token and use the Maps SDK.
How do I show the user's location on the map?
Add the location permission string to Info.plist, request `requestWhenInUseAuthorization()` from CLLocationManager, then enable the location puck with `mapView.location.options.puckType = .puck2D()`.

Generated from the current SKILL.md. These answers refresh after source changes.