我使用SwiftUI编写应用,并希望使用自定义注释制作MapView
import SwiftUI
import MapKit
import CoreLocation
struct MapView: UIViewRepresentable {
var center: CLLocationCoordinate2D
func makeUIView(context: Context) -> MKMapView {
let mapview = MKMapView(frame: .zero)
mapview.mapType = .hybrid
return mapview
}
func updateUIView(_ uiView: MKMapView, context: Context) {
let span = MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)
let region = MKCoordinateRegion(center: center, span: span)
uiView.setRegion(region, animated: true)
}
}
如何覆盖结构中的func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
?