【发布时间】:2014-08-04 20:46:03
【问题描述】:
我正在尝试将 Listing 6-9 中的 MapKit MKPolygon 引用中的 Objective-C 代码转换为 Swift。
当我调用函数时使用
init(coordinates:count:)
初始化函数,我得到错误:
调用中的参数“interiorPolygons”缺少参数
当我使用interiorPolygons 参数调用函数时,我得到了错误:
调用中的额外参数
这是我正在使用的代码。
var points: [CLLocationCoordinate2D] = [CLLocationCoordinate2D]()
points[0] = CLLocationCoordinate2DMake(41.000512, -109.050116)
points[1] = CLLocationCoordinate2DMake(41.002371, -102.052066)
points[2] = CLLocationCoordinate2DMake(36.993076, -102.041981)
points[3] = CLLocationCoordinate2DMake(36.99892, -109.045267)
var poly: MKPolygon = MKPolygon(points, 4)
poly.title = "Colorado"
theMapView.addOverlay(poly)
更新:
points.withUnsafePointerToElements() { (cArray: UnsafePointer<CLLocationCoordinate2D>) -> () in
poly = MKPolygon(coordinates: cArray, count: 4)
}
似乎摆脱了编译器错误,但仍然没有添加覆盖。
【问题讨论】:
标签: ios swift mapkit ios8 mkpolygon