我正在尝试从坐标列表中绘制MKMapView上的路径,但我得到两个错误 这是代码(错误行有注释):
var routes = [CoordVO]();
routes.append(pn)
routes.appe...
var a = UInt(sizeof(CLLocationCoordinate2D)) * UInt(routes.count)
var pointArr = malloc(a)
for var idx = 0; idx < routes.count; idx++ {
var obj = routes[idx]
var workingCoordinate:CLLocationCoordinate2D!
workingCoordinate.latitude=obj.lat
workingCoordinate.longitude=obj.lng
var point = MKMapPointForCoordinate(workingCoordinate)
pointArr[idx] = point; // MKMapPoint is not convertible to Void
}
var routeLine = MKPolyline(points: pointArr, count: routes.count) // Void is not identical to MKMapPoint
self.mapView.addOverlay(routeLine)
free(pointArr);
答案 0 :(得分:0)
查看MKPolyline
init方法的定义:
init!(points points: UnsafeMutablePointer<MKMapPoint>, count count: Int)
它需要UnsafeMutablePointer<MKMapPoint>
,但malloc
会创建UnsafeMutablePointer<Void>
,从而导致问题。