sgade/swiftui-mapview
[MKMapView](https://developer.apple.com/documentation/mapkit/mkmapview) in SwiftUI.
Install
Using Xcode, select File -> Swift Packages -> Add Package Dependency and enter https://github.com/sgade/swiftui-mapview.
Usage
In your view, add the map. See the example project for how to integrate the map view.
import SwiftUIMapView
struct ContentView: View {
var body: some View {
MapView()
}
}Configuration
Map type
MapView(mapType: .standard)User location
Showing the current user location
The current location can be shown on the map. Note that the application requires permission to access the current user location. See the documentation on MapView.showsUserLocation for more information.
MapView(showsUserLocation: true)Tracking the user's location
MapView(userTrackingMode: .follow)Setting the visible region
The binding passed in for region defines the visible map region. Use it to define the visible center and zoom. Setting it to nil will use the map's default region when loaded. It is also updated when the visible region changes.
@State var region: MKCoordinateRegion?
MapView(region: $region)Annotations
Adding annotations
Annotations are represented as objects of a custom class that implements the MapViewAnnotation protocol. It might be helpful to subclass from existing classes like MKPlacemark.
let annotations: [MapViewAnnotation] = ...
MapView(annotations: annotations)Selecting annotations
A list of selected annotations can be passed in via a binding.
@State var selectedAnnotations: [MapViewAnnotation] = []
MapView(selectedAnnotations: $selectedAnnotations)Contributing
See the contributing guide.
License
This project is licensed unter the terms of the MIT license. See LICENSE for more information.
Package Metadata
Repository: sgade/swiftui-mapview
Default branch: main
README: README.md