GMSMapView animateToCameraPosition zoom in - zoom out animation
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_after
method, first you can define a method to delay how many seconds you want:
func delay(#seconds: Double, completion:()->()) { let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64( Double(NSEC_PER_SEC) * seconds )) dispatch_after(popTime, dispatch_get_main_queue()) { completion() }}
Then you can zoom out your camera, move to a location, then zoom in with the delay
method:
delay(seconds: 0.5) { () -> () in var zoomOut = GMSCameraUpdate.zoomTo(kGMSMinZoomLevel) mapView.animateWithCameraUpdate(zoomOut) delay(seconds: 0.5, { () -> () in var vancouver = CLLocationCoordinate2DMake(49.26,-123.11) var vancouverCam = GMSCameraUpdate.setTarget(vancouver) mapView.animateWithCameraUpdate(vancouverCam) delay(seconds: 0.5, { () -> () in var zoomIn = GMSCameraUpdate.zoomTo(kGMSMaxZoomLevel) mapView.animateWithCameraUpdate(zoomIn) }) })}
You use your own zoom value, I use kGMSMinZoomLevel
and kGMSMaxZoomLevel
here.
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) }) }) }