2013-10-01 40 views
8

。我想每5秒更新一次pin的gps座標。目前我只是更新GMSMarker的位置屬性。但它會產生跳躍效應。我想在地圖上順利移動標記。
這裏是我的代碼更新標記如何平滑移動GMSMarker沿着座標在目標c我使用谷歌地圖sdk目標c

-(void)updateLocationoordinates(CLLocationCoordinate2D) coordinates 
{ 
    if (marker == nil) { 
     marker = [GMSMarker markerWithPosition:coordinates]; 
     marker.icon = [UIImage imageNamed:CAR_FOUND_IMAGE]; 
     marker.map = mapView_; 
    } else 
    marker.position = coordinates; 
} 

回答

28
的位置

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

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

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

請參閱SDK示例應用程序中的AnimatedCurrentLocationViewController.{c,m}

+0

謝謝@Brett不需要任何形式的動畫的更新。我更新了谷歌SDK,然後這些動畫工作正常。 – Sadia

+0

對我來說,這實際上沒有奏效。實際上,它完全破壞了.position屬性的動畫。好消息是,*完全是我想要的:一種關閉.position屬性動畫的方法。萬分感謝!作爲參考,我將動畫持續時間設置爲0.0,但具有非0值仍未設置動畫。 – u2Fan

+1

好 - 我撒謊了。它和海報提到的完全一樣。我只是搞砸了我的測試。但是,我注意到編輯我的第一條評論爲時已晚。 – u2Fan

0

只是初始化標記鑑於沒有負荷,當你想要做這樣

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    ..write code here 
     marker = [[GMSMarker alloc] init]; 
} 
    marker.position = CLLocationCoordinate2DMake([latitudue doubleValue], [longitude doubleValue]); 
+0

請格式化您的代碼。 – thewaywewere