8

次のようなものを使用して配列を構築する必要があります。

CLLocationCoordinate2D  points[4];


    points[0] = CLLocationCoordinate2DMake(41.000512, -109.050116);

    points[1] = CLLocationCoordinate2DMake(41.002371, -102.052066);

    points[2] = CLLocationCoordinate2DMake(36.993076, -102.041981);

    points[3] = CLLocationCoordinate2DMake(36.99892, -109.045267);

問題は、配列に含まれるアイテムの数がわからないため、カウントを指定できることです。CLLocationCoordinate2D 配列を作成し、最終的な合計がどうなるかを知らずに新しい座標を挿入する方法はありますか?

編集: 私の最終的な目標は、CLLocationCoordinate2D 配列を必要とする polylineWithCoordinates メソッドを使用して、座標を使用して MKPolyline を作成することです。

4

2 に答える 2

16
// unpacking an array of NSValues into memory
CLLocationCoordinate2D *points = malloc([mutablePoints count] * sizeof(CLLocationCoordinate2D));
for(int i = 0; i < [mutablePoints count]; i++) {
    [[mutablePoints objectAtIndex:i] getValue:(points + i)];
}

MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:points count:[mutablePoints count]];
free(points);
于 2010-08-12T22:33:57.037 に答える
0

それらをNSValueオブジェクトに入れ、NSMutableArray.

于 2010-08-12T21:17:48.767 に答える