jbobrow
jbobrow

Reputation: 81

Having trouble using MKPolygon or polygonWithCoordinates (Swift)

I am a bit confused, possibly by XCode suggesting that I should have a third parameter for MKPolygon, or only 2 params when I at the third. I am sure it is something else small and silly in my formatting, but any help as to the best way to create an MKPolygon from an array of Coordinates would be wonderful!

// receive array of coordinates and update polygon of quarantine
func updateQuarantine(coords:[CLLocationCoordinate2D]) {

    let polyLine:MKPolygon = MKPolygon(coordinates: &coords, count: coords.count)           

    self.mapView.addOverlay(polyLine)  

    self.mapView.removeOverlay(quarantinePolygon)

    quarantinePolygon = polyLine
}

Upvotes: 0

Views: 825

Answers (1)

Martin R
Martin R

Reputation: 540005

To pass the in-out value &coords to MKPolygon(), the array has to be declared as a variable (var):

func updateQuarantine(var coords:[CLLocationCoordinate2D]) {
//             HERE ---^

    let polyLine = MKPolygon(coordinates: &coords, count: coords.count)

    // ...    
}

Function parameters are by default constant, i.e. as if they were defined with let.

Upvotes: 1

Related Questions