添加func mapView(_ mapView:MKMapView,viewFor注释:MKAnnotation)-> MKAnnotationView?在SwiftUI中

时间:2020-04-21 14:47:31

标签: swift overriding swiftui mapkit

我使用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?

0 个答案:

没有答案