2

I tried all the animation methods provided by google maps. But I fail to animate the zoomlevel of map view. I have tried mapView.animateToZoom(15). Also

UIView.animateWithDuration(5.0, animations: {
                    let zoomIn = GMSCameraUpdate.zoomTo(15)
                    self.mapView.animateToZoom(15)
                })

But I fail to achieve the animation. I also followed GMSMapView animateToCameraPosition zoom in - zoom out animation

But no hope. Can anyone help please?

Community
  • 1
  • 1
Amrit Sidhu
  • 1,870
  • 1
  • 18
  • 32
  • I guess it is because `GMSMapView` is not consist of UIKit. Anyway, `animateToZoom` is already a animation. Why do you need it in `UIView`'s animation block? – Ryan Apr 14 '16 at 21:25
  • I was just trying by using it in UIView's animation block! Simply using self.mapView.animateToZoom(15) doesnot animate the map View – Amrit Sidhu Apr 15 '16 at 03:44

2 Answers2

6

After a lot of struggle I managed to animate the GMSMapView: Here is the code for the reference:

mapView.camera = GMSCameraPosition.cameraWithLatitude(58.998400,longitude: 10.035604, zoom: 1)


        CATransaction.begin()
        CATransaction.setValue(2.0, forKey: kCATransactionAnimationDuration)
        let city = GMSCameraPosition.cameraWithLatitude(58.998400,longitude: 10.035604, zoom: 15)
        self.mapView.animateToCameraPosition(city)
        CATransaction.commit()
Amrit Sidhu
  • 1,870
  • 1
  • 18
  • 32
2

Update for swift 5

CATransaction.begin()
CATransaction.setValue(1.0, forKey: kCATransactionAnimationDuration)
let city = GMSCameraPosition.camera(withTarget:  CLLocationCoordinate2D(latitude, longitude:logitude), zoom: 16)
self.mapView.animate(to: city)
CATransaction.commit()
aqsa arshad
  • 801
  • 8
  • 27