質問

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

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);

問題は、アレイに何のアイテムがあるかわからないので、カウントを指定できることです。 CllocationCoodinate2Dアレイを作成し、最終合計が何であるかを知らずに新しい座標を挿入する方法はありますか?

編集:私の最終目標は、CllocationCoodinate2Dアレイが必要なPolylineWithCoordinatesメソッドを使用して、座標を使用してMkpolylineを作成することです。

役に立ちましたか?

解決

// 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);

他のヒント

それらをボックスアップします NSValue オブジェクトとそれらをandに投げます NSMutableArray.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top