MKPolygon initialization error "Missing argument for 'innerPolygons' parameter in call" / "Optional argument in call"

I am trying to convert Objective-C code to a MapKit MKPolygonlink in Listing 6-9 in Swift.

When I call a function with

 init(coordinates:count:)

Init function, I get an error message:

Missing argument for 'innerPolygons' parameter in call

When I call a function with internalPolygons argument, I get an error:

Additional arguments in the call

Here is the code I'm using.

 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)

UPDATE:

 points.withUnsafePointerToElements() { (cArray: UnsafePointer<CLLocationCoordinate2D>) -> () in
            poly = MKPolygon(coordinates: cArray, count: 4)
        }

It seems to get rid of a compiler error, but does not add an overlay.

+3
source share
1

:

var poly: MKPolygon = MKPolygon(points, 4)

, points .

:

var poly: MKPolygon = MKPolygon(coordinates: &points, count: 4)


( points.withUnsafePointerToElements... .)


, var points: [CLLocationCoordinate2D] = [CLLocationCoordinate2D]() . points[0] = ... , . points.append():

points.append(CLLocationCoordinate2DMake(41.000512, -109.050116))
points.append(CLLocationCoordinate2DMake(41.002371, -102.052066))
points.append(CLLocationCoordinate2DMake(36.993076, -102.041981))
points.append(CLLocationCoordinate2DMake(36.99892, -109.045267))

:

var points = [CLLocationCoordinate2DMake(41.000512, -109.050116),
              CLLocationCoordinate2DMake(41.002371, -102.052066),
              CLLocationCoordinate2DMake(36.993076, -102.041981),
              CLLocationCoordinate2DMake(36.99892, -109.045267)]


, , rendererForOverlay ( map view delegate):

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
    if overlay is MKPolygon {
        var polygonRenderer = MKPolygonRenderer(overlay: overlay)
        polygonRenderer.fillColor = UIColor.cyanColor().colorWithAlphaComponent(0.2)
        polygonRenderer.strokeColor = UIColor.blueColor().colorWithAlphaComponent(0.7)
        polygonRenderer.lineWidth = 3
        return polygonRenderer
    }

    return nil
}


: points, coordinates , points , MKMapPoint structs, (points:count:) .

+4

All Articles