MKMapPoint无法转换为Void错误

时间:2015-03-11 10:43:44

标签: objective-c xcode swift mkmapview mkpolyline

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

1 个答案:

答案 0 :(得分:0)

查看MKPolyline init方法的定义:

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

它需要UnsafeMutablePointer<MKMapPoint>,但malloc会创建UnsafeMutablePointer<Void>,从而导致问题。