How to declare MKPolygon

Hey guys, such a seemingly simple problem, but apparently too complicated for me. I am trying to create one instance of MKPolygon, and that is not too good. 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 get a bunch of errors in a string in which I initialize an array ( incompatible type for argument 1...). Any idea what's wrong? Thanks in advance!

+3
source share
1 answer

MKMapPoint is a simple c-structure, and you cannot directly add it to the objective-c container.

In your case, you do not need to do this, since it +polygonWithPoints:does not require NSArray, and c-array as the 1st parameter. The correct way to create a polygon would be:

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

Source: https://habr.com/ru/post/1778249/


All Articles