Полилиния не отображается в swiftUI - PullRequest
0 голосов
/ 29 апреля 2020

Привет всем, я работал несколько дней, чтобы показать прямую линию на моей карте. Я использую swiftUI и mapkit для рендеринга map. что я хочу достичь - это straight line между двумя аннотациями, они показаны на map.

DIT - это код d ie ik op dit момент heb. Ik h oop dut jull ie mij kunnen helpen want ik kom er niet uit.

import MapKit

struct MapViewWorldDetail: UIViewRepresentable {

    var StartCoordinate: CLLocationCoordinate2D
    var EndCoordinate: CLLocationCoordinate2D
    var name: String
    @Binding var region: CLLocationCoordinate2D

    func makeUIView(context: Context) -> MKMapView {
        MKMapView(frame: .zero)
    }

    func updateUIView(_ view: MKMapView, context: Context) {

        let span = MKCoordinateSpan(latitudeDelta: 50, longitudeDelta: 50)
        let region = MKCoordinateRegion(center: self.region, span: span)
//      view.mapType = MKMapType.satelliteFlyover;
        view.setRegion(region, animated: true)

        let annotation = MKPointAnnotation()
        annotation.coordinate = StartCoordinate
        annotation.title = name
        view.addAnnotation(annotation)

        let annotationEnd = MKPointAnnotation()
        annotationEnd.coordinate = EndCoordinate
        annotationEnd.title = name
        view.addAnnotation(annotationEnd)

        let aPolyline = MKGeodesicPolyline(coordinates: [StartCoordinate, EndCoordinate], count: 2)
        view.addOverlay(aPolyline)
    }
}
...