座標を含むオブジェクトのNSArray
がある場合、polygonWithPoints:count:
の代わりにpolygonWithCoordinates:count:
メソッドを使用する方が簡単になります。
polygonWithCoordinates:count:
メソッドは、CLLocationCoordinate2D
構造体のC配列を受け入れます。 CLLocation
オブジェクト内のcoordinate
プロパティもCLLocationCoordinate2D
です。
それでもpolygonWithPoints:count:
を使用する場合は、MKMapPoint
にCLLocation
でcoordinate
プロパティを変換するMKMapPointForCoordinate
機能を使用することができます。
どちらの方法でも、適切な構造体のC配列を作成し、NSArray
をループしてC配列の各項目を設定します。その後、polygonWithCoordinates
またはpolygonWithPoints
と呼んでください。
This answerのコード例はpolygonWithCoordinates
です。 viewForOverlay
デリゲートメソッドを実装することを忘れ(およびマップビューのdelegate
プロパティが設定されていることを確認してください)しないでください
CLLocation *coordObj = (CLLocation *)[coordinateData objectAtIndex:i];
coords[i] = coordObj.coordinate;
:この例では、あなたがにfor
ループ内の2行を変更します。