Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling Animation Duration in Google Maps for iOS

The documentation for Google Maps for iOS states that:

Call one of several methods that allow you to animate the camera moving to a new location. You can control the duration of the animation with CoreAnimation.

For the life of me, I can't figure out how to control the animation duration. I have tried using UIView animations, like:

    [UIView animateWithDuration: 5 animations:^{          GMSCameraPosition *camera = [self newCamera];         self.mapView.camera = camera;     } completion:^(BOOL finished) {     }]; 

And I have looked at CALayer animations in CoreAnimation. However, I don't know how you would apply a layer animation to the map view.

Can someone point me in the right direction please?

like image 336
Colin Phillips Avatar asked Mar 27 '13 15:03

Colin Phillips


People also ask

Is Google Map free for IOS?

Cost and data. Google does not charge you to use the Google Maps app. Because Google Maps might use your phone or tablet's data connection, your mobile service provider might charge you for your data usage.

How do I add a marker to Google Maps on Iphone?

Type the name of a location or address. This displays a list of matching search results from Google Maps below the search bar at the top. Alternatively, you can tap the blue plus (+) icon in the lower-right corner of the map. Then tap Add new point. Drag the marker on the map to where you want to add a marker.


2 Answers

I found the answer ... you can control the animation duration by wrapping one of the animate* methods in a CATransaction, like this:

   [CATransaction begin];    [CATransaction setValue:[NSNumber numberWithFloat: 1.0f] forKey:kCATransactionAnimationDuration];    // change the camera, set the zoom, whatever.  Just make sure to call the animate* method.    [self.mapView animateToCameraPosition: [self newCamera]];    [CATransaction commit]; 
like image 156
Colin Phillips Avatar answered Oct 05 '22 20:10

Colin Phillips


for Swift 3.0:

CATransaction.begin() CATransaction.setValue(1.5, forKey: kCATransactionAnimationDuration) // your camera code goes here, example: // mapView.animate(with: update) CATransaction.commit() 

The bigger the value (1.5 in this case), the slower the animation.

like image 44
lenooh Avatar answered Oct 05 '22 22:10

lenooh