2017-07-26 1 views
0

を逆にすると、次のとおりです。ドキュメントGMSMutablePathによるGMSMutablePathアレイ

GMSMutablePath is a dynamic (resizable) array of CLLocationCoordinate2D. [Google Documentation] 

https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_mutable_path

私はパスの座標の順序を逆にしたいです。通常、私が使用する配列を持つ:

[[array123 reverseObjectEnumerator] allObjects]; 

が、NSArrayの機能のどれもがそれに動作しませんし、私はNSArrayのかNSMutableArrayのにキャストしてみた場合、私はちょうど赤い旗を取得します。

GMSMutablePathの要素の順序を逆にする方法、またはNSArrayに正しくキャストする方法を教えてください。

+1

NSMutableArrayから継承されたオブジェクトではありません。あなたはそのようにキャストすることはできません。単純にforループで 'replaceCoordinateAtIndex:withCoordinate:'を使って手作業でやってみましょう。これはおそらく次のようになります: 'for(NSUInteger i1 = 0; i1 <[myPath count]/2; i1 ++){NSUInteger i2 = [myPath count] -i1; CLLocationCoordinate2D * coord1 = [myPath coordinateAtIndex:i1]; CLLocationCoordinate2D * coord2 = [myPath coordinateAtIndex:i2]; [myPath replaceCoordinateAtIndex:i1 withCoordinate:coord2]; [myPath replaceCoordinateAtIndex:i2 withCoordinate:coord1];} ' – Larme

+0

@Larmeそれは動作します。ありがとう – johnsonjp34

答えて

1

GMSMutablePathNSMutableArrayから継承されないため、NSMutableArrayとしてキャストできません。 できることは手動で行うことです。 NSMutableArrayとしたい場合はexchangeObjectAtIndex:withObjectAtIndex:と呼ぶことができますが、GMSMutablePathはそのメソッドと同等の機能を提供していないようですので、もっと明示的に行うことができます。

for (NSUInteger i1 = 0; i1 < [myPath count]/2; i1 ++) 
{ 
    NSUInteger i2 = [myPath count]-i1; 
    CLLocationCoordinate2D *coord1 = [myPath coordinateAtIndex:i1]; 
    CLLocationCoordinate2D *coord2 = [myPath coordinateAtIndex:i2]; 
    [myPath replaceCoordinateAtIndex:i1 withCoordinate:coord2]; 
    [myPath replaceCoordinateAtIndex:i2 withCoordinate:coord1]; 
} 
関連する問題