SwiftUIAdvancedMap

A wrapper around MKMapView with more functionality than Map.
Points and Overlays |
Camera |
Styling |
 |
 |
 |
Feature |
AdvancedMap |
MapKit.Map |
Tap/Long Press Gestures with Map coordinates passed into the Handlers. |
✅ |
❌ |
Annotations with Drag and Drop support |
✅ (UIKit Annotation Views) |
✅ (SwiftUI Annotation Views) |
Overlays |
✅ (UIKit Overlay Views) |
❌ |
Specify EdgeInsets for UI overlays |
✅ |
❌ |
Display User Location |
✅ (via AnnoatationViewFactory ) |
✅ (as an initialization parameter) |
Region State Changing Handler, a callback that informs when a map change Animation in progress. |
✅ |
❌ |
Binding to Optional map region so map is initially positioned around country bounding box. |
✅ |
❌ |
MKMapCamera support |
✅ |
❌ |
Tap or Click Gesture with Coordinate on Map.
struct TappableMap: View {
var body: some View {
// `.constant(nil)` uses MKMapView's behavior of starting the map over the phone's current country.
// Still scrollable by default.
AdvancedMap(mapRect: .constant(nil))
.onTapOrClickMapGesture { coordinate in
print("Tapped map at: \(coordinate)")
}
}
}
Rendering Annotations
struct TappableMap: View {
static let annotationViewFactory = AnnotationViewFactory(
register: { mapView in
mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: String(describing: MKPointAnnotation.self))
},
view: { mapView, annotation in
mapView.dequeueReusableAnnotationView(withIdentifier: String(describing: MKPointAnnotation.self), for: annotation)
}
)
@State var mapVisibility: MapVisibility?
@State var annotations: [MKPointAnnotation] = [MKPointAnnotation]()
var body: some View {
AdvancedMap(mapVisibility: $mapVisibility)
.annotations(annotations, annotationViewFactory: Self.annotationViewFactory)
.onTapOrClickMapGesture { coordinate in
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotations.append(annotation)
}
}
}
Inspired by, and sometimes stealing from, the following projects:
SwiftUIAdvancedMap
A wrapper around MKMapView with more functionality than Map.
AdvancedMap
MapKit.Map
(UIKit Annotation Views)
(SwiftUI Annotation Views)
(UIKit Overlay Views)
(via
AnnoatationViewFactory
)(as an initialization parameter)
MKMapCamera
supportTap or Click Gesture with Coordinate on Map.
Rendering Annotations
Inspired by, and sometimes stealing from, the following projects: