2016-09-19 76 views
1

我能夠與位置陣列借鑑GMSPolyline上的GoogleMaps這樣如何在iOS中緩慢而平穩地繪製GMSPolyline?

GMSMutablePath *path = [GMSMutablePath path]; 

    for (int i = 0; i <anotherArray.count; i++) { 

     NSString *string1 = [anotherArray2 objectAtIndex:i]; 
     NSString *string2 = [anotherArray objectAtIndex:i]; 
     [path addCoordinate:CLLocationCoordinate2DMake(string1.doubleValue,string2.doubleValue)]; 
    } 

     GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path]; 
     rectangle.strokeColor = [UIColor blueColor]; 
     rectangle.map = mapView_; 
     rectangle.strokeWidth = 2.0f; 

但我從後端服務器獲取位置。

因此,我必須每10秒刷新一次,獲取新位置並將其添加到現有路徑。這些都工作正常。

但是,當我向現有路徑添加新位置時移動速度非常快。

因爲我有一個GMSMarker開始的路徑,它看起來像從一個地方跳到另一個地方。

那麼我怎樣才能讓GMSMarker像從一個地方慢慢移動到另一個地方一樣動畫呢?

回答

0

請檢查tutorial。它說明如何使用GMSPolyline類在地圖上繪製路線。從這個related SO thread

更改else塊是更多的東西是這樣的:

[CATransaction begin]; 
[CATransaction setAnimationDuration:2.0]; 
marker.position = coordindates; 
[CATransaction commit]; 

我們使您可以使用Core Animation 製作動畫谷歌地圖。

對於已加工的樣品,請參閱 AnimatedCurrentLocationViewController.{c,m} SDK樣品 申請。

同樣根據此SO post,避免使用1px的stroke-width行。相反,使用4px中風寬度。您也可以檢查此GitHub sample

+0

感謝您的詳細澄清。我檢查 – Himanth