Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to smoothly move GMSMarker along coordinates in Objective c

I'm using google map sdk. I want to update gps coordinates of pin after each 5 seconds. Currently I'm just updating position attribute of GMSMarker. But it gives jump effect. I want to move marker smoothly on map.
Here is my code to update position of marker

-(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; 
}
like image 363
Sadia Avatar asked Oct 01 '13 11:10

Sadia


2 Answers

Brett's Answer in swift -3 and 4

CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
marker.position = coordindates
CATransaction.commit()
like image 188
Ajumal Avatar answered Oct 31 '22 22:10

Ajumal


Change your else block to be something more like this:

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

We enable you to use Core Animation for animating Google Maps.

For a worked sample, please see AnimatedCurrentLocationViewController.{c,m} in the SDK sample application.

like image 35
Brett Avatar answered Oct 31 '22 22:10

Brett