I am using Google maps services in iOS (Swift) and Android. In android, the map view has a method called animatreCamera that has an animation in which the movement has a "zoom out - zoom in" effect (if both cameras have the same zoom, the map view will zoom out the first part of the movement and then zoom in the second part). I want to achieve this effect with the GMSMapView in iOS, I have tried te following methods: animateToCameraPosition, animateToLocation, animateWithCameraUpdate, moveCamera and setting the camera by mapView.camera = GMSCameraPosition(target: location, zoom: 15, bearing: 0, viewingAngle: 0) and none of them have this animation. If possible, how can I achieve this animation when moving the camera?
GMSMapView animateToCameraPosition zoom in - zoom out animation
7.9k views Asked by Oscar Vasquez At
        	2
        	
        There are 2 answers
0
                
                        
                            
                        
                        
                            On
                            
                            
                                                    
                    
                Swift 4:
   func delay(seconds: Double, closure: @escaping () -> ()) {
    DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
        closure()
    }
  }
Then call it :
    delay(seconds: 0.5) { () -> () in
            let zoomOut = GMSCameraUpdate.zoom(to: 10)
            self.mapView.animate(with: zoomOut)
            self.delay(seconds: 0.5, closure: { () -> () in
            var vancouver = CLLocationCoordinate2DMake(49.26,-123.11)
            var vancouverCam = GMSCameraUpdate.setTarget(vancouver)
            self.mapView.animate(toLocation: vancouverCam)
            self.delay(seconds: 0.5, closure: { () -> () in
                 let zoomIn = GMSCameraUpdate.zoom(to: 15)
                 self.mapView.animate(with: zoomIn)
                })
            })
        }
                        
I think there is no direct way you can archive the same animation in the Google Maps iOS SDK.
A workaround can use iOS's
dispatch_aftermethod, first you can define a method to delay how many seconds you want:Then you can zoom out your camera, move to a location, then zoom in with the
delaymethod:You use your own zoom value, I use
kGMSMinZoomLevelandkGMSMaxZoomLevelhere.