我有一个坐标对象数组,想要在Swift 3中的Mapkit中将它们(按照它们的顺序)连接成Polyline。我该怎么做呢?这是我的数据结构
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;
}
)
此前关于此主题的讨论现已过时。
答案 0 :(得分:1)
您必须将其转换为[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)