いくつかの(不明な数の)MKpointAnnotationsをマップに配置した後、ユーザーがポリゴンを作成できるようにしたいユーザーがボタンをタップするとアクティブになるジェスチャ認識機能を配置したので、注釈が配置されますが、これらを次のように使用する方法MKPolygonのコーナー?ポリゴンの角を保存するためのコードの下。これは、いくつかの変更を行った後です。アプリがクラッシュし、クラッシュレポーターがインデックスが範囲外であると表示します。角はGestureRecognizerを介して作成されたMKPointAnnotationです。
-(IBAction)addCorner:(id)sender
{
NSMutableArray *addCorners = [[NSMutableArray alloc] init];
[addCorners addObject:pointAnnotation];
ptsArray = addCorners;
}
-(IBAction)addPolygonOverlay:(id)sender
{
int cornersNumber = sizeof(ptsArray);
MKMapPoint points[cornersNumber];
for (int i=0; i<cornersNumber; i++) {
points[i] = MKMapPointForCoordinate([[ptsArray objectAtIndex:i] coordinate]);
}
MKPolygon *polygon = [MKPolygon polygonWithPoints:points count:cornersNumber];
[mapview addOverlay:polygon];
}