0

我正在尝试从坐标列表中在 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);
4

1 回答 1

0

MKPolylineinit方法的定义:

init!(points points: UnsafeMutablePointer<MKMapPoint>, count count: Int)

它需要一个UnsafeMutablePointer<MKMapPoint>,但malloc你创建一个UnsafeMutablePointer<Void>,这会导致问题。

于 2015-03-11T11:14:22.943 回答