A wrapper around MKMapView with more functionality than Map.
Feature | AdvancedMap |
MapKit.Map |
---|---|---|
Tap Gesture with Map coordinates passed into the Handler. | ✅ | ❌ |
Annotations | ✅ (UIKit Annotation Views) |
✅ (SwiftUI Annotation Views) |
Drag and Drop Annotations | ✅ | ❌ |
Overlays | ✅ (UIKit Overlay Views) |
❌ |
Specify EdgeInsets for UI overlays | ✅ | ❌ |
Display User Location | ✅ (via AnnoatationViewFactory ) |
✅ (as an initialization parameter) |
User Tracking Mode | ❌ | ✅ |
Region State Changing Handler (Animation in progress) |
✅ | ❌ |
Animate Changes Control | ✅ | ❌ |
Binding to Optional map region so map is initially positioned around country bounding box. | ✅ | ❌ |
struct TappableMap: View {
@State var rect: MKMapRect? = nil
var body: some View {
AdvancedMap(mapRect: $rect) { coordinate in
print("Tapped on map at: \(coordinate)")
}
}
}
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 rect: MKMapRect? = nil
@State var annotations: [MKPointAnnotation] = [MKPointAnnotation](https://raw.github.com/sena-mike/SwiftUIAdvancedMap/main/)
var body: some View {
AdvancedMap(
mapRect: $rect,
annotations: annotations,
annotationViewFactory: TappableMap.annotationViewFactory
) { coordinate in
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotations.append(annotation)
}
}
}
Inspired by, and sometimes stealing from, the following projects:
link |
Stars: 5 |
Last commit: 5 days ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics