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?
它不是從'NSMutableArray'繼承的對象。你不能這樣做。只需用'replaceCoordinateAtIndex:withCoordinate:'手動執行,用一個簡單的for循環:也許是這樣的: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
@Larme這很有效。謝謝 – johnsonjp34