Stunner
Stunner

Reputation: 12194

How To Declare an MKPolygon

Ey guys, so a seemingly simple problem but apparently too complicated for me. I am trying to create one instance of MKPolygon and it ain't going too well. Here is the code:

MKMapPoint point1 = {38.53607,-121.765793};
 MKMapPoint point2 = {38.537606,-121.768379};
 MKMapPoint point3 = {38.53487,-121.770578};
 NSArray *mapPointArr = [[NSArray alloc] initWithObjects:point1,point2,point3,nil count:3]; //errors here

 MKPolygon *polygon = [MKPolygon polygonWithPoints:mapPointArr count:3];

I am getting a bunch of errors on the line at which I initialize the array(incompatible type for argument 1...). Any idea what's wrong? Thanks in advance!

Upvotes: 3

Views: 2199

Answers (1)

Vladimir
Vladimir

Reputation: 170839

MKMapPoint is a plain c-structure and you can't add it to objective-c container directly.

In your case you do not need to do that as +polygonWithPoints: requires not a NSArray, but a c-array as 1st parameter. Proper way to create polygon will be:

MKMapPoint points[3] = {{38.53607,-121.765793}, {38.537606,-121.768379}, {38.53487,-121.770578}};
MKPolygon *polygon = [MKPolygon polygonWithPoints:points count:3];

Upvotes: 5

Related Questions