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];
我在初始化数组的行上遇到了一堆错误(incompatible type for argument 1
...)。知道什么是错的吗?提前谢谢!
答案 0 :(得分:5)
MKMapPoint是一个简单的c结构,你不能直接将它添加到objective-c容器中。
在您的情况下,您不需要这样做,因为+polygonWithPoints:
不需要NSArray,而是c-array作为第一个参数。创建多边形的正确方法是:
MKMapPoint points[3] = {{38.53607,-121.765793}, {38.537606,-121.768379}, {38.53487,-121.770578}};
MKPolygon *polygon = [MKPolygon polygonWithPoints:points count:3];