嗨,我编写了这段代码来在某个点之间绘制一条折线:
var arrayToDraw: Array<Any> = []
var forpolyline: Array<CLLocationDegrees> = []
var forpolyline2: CLLocationCoordinate2D = CLLocationCoordinate2D.init()
func showRoute() {
for h in 0...(orderFinalDictionary.count - 1){
arrayToDraw = orderFinalDictionary[h].value
print(arrayToDraw)
var arrayToDrawCount = arrayToDraw.count
for n in 0...(arrayToDrawCount - 1){
forpolyline = (arrayToDraw[n] as! Array<CLLocationDegrees>)
forpolyline2.latitude = (forpolyline[0])
forpolyline2.longitude = (forpolyline[1])
print(forpolyline2)
var geodesic = MKPolyline(coordinates: &forpolyline2, count: 1)
self.mapView.add(geodesic)
}
}
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let renderer = MKPolylineRenderer(polyline: overlay as! MKPolyline)
renderer.strokeColor = UIColor.red
renderer.lineWidth = 3
return renderer
}
它从字典中获取坐标,将其放入数组(arraToDraw)中,我使用 forpolyline 和 forpolyline2 来转换值。
现在的问题是它只在坐标上画点我怎么能连接呢?