使用坐标列表在 Mapkit 上画一条线

Draw a line on Mapkit using list of coordinates

我有一个坐标对象数组,想在 Swift 的 Mapkit 中将它们连接起来(按它们的顺序)作为折线 3. 我该怎么做?这是我的数据结构

List<Location> (
    [0] Location {
        lat = 37.33477977;
        long = -122.03369603;
    },
    [1] Location {
        lat = 37.33477977;
        long = -122.03369603;
    },
    [2] Location {
        lat = 37.33477977;
        long = -122.03369603;
    },
    [3] Location {
        lat = 37.33305632;
        long = -122.05318781;
    },
    [4] Location {
        lat = 37.33298105;
        long = -122.0535463;
    }
)

以前关于这个话题的讨论现在已经过时了。

您必须将其转换为 [CLLocation] 的数组看看这个 similar question:

var locations = [CLLocation(latitude: 37.582691, longitude: 127.011186), CLLocation(latitude: 37.586112,longitude: 127.011047), CLLocation(latitude: 37.588212, longitude: 127.010438)]
        var coordinates = locations.map({(location: CLLocation) -> CLLocationCoordinate2D in return location.coordinate})
        var polyline = MKPolyline(coordinates: &coordinates, count: locations.count)