Gmsmapview Animatetocameraposition Zoom in - Zoom Out Animation

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.

Animating GMSMapView

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()

Change the camera position of GMS Map View with animation

Try the below code. You may update it for latest swift syntax.

    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()

GMSMapView is not zooming in

I guess you are doing something wrong here. You said that

Originally the zoom level is at 4. When I set the coordinate and zoom level, it stays zoomed out despite my debugger saying the zoom level is 2.

Just to be clear, zoom level 4 is > zoom level 2. If you want your map to be zoomed in try using higher values i.e. around 15, 16 etc.

Hope it helps.

GMSMapView: center on coordinate and zoom out to reveal user location

To display the POI in the centre, and the user location at an edge of the map, you should derive a third location point mirroring the relative distance of user llc from the POI on the other side of the POI.

if we are allowed to ignore the earth's curvature this is simple vector addition

I.e.

loc3 = poiLoc + (poiLoc - userLoc) 
= 2*poiLoc - userLoc;

Then your map rect is defined by the userLoc and loc3.

Map camera position changes sharply without animation

I think the problem with this is that calling setCamera will snap to the new zoom level without animating - and so the following call to animateToCameraPosition won't actually animate anything, as the camera is already at that position.

However, if you removed the call to setCamera then you'd probably end up in an infinite loop, as the call to animateToCameraPosition won't actually update the camera until some time later (as the animation plays), and so on the next iteration of the loop the markers would still all be visible.

What you need to do is calculate the final zoom level that you need, and then make a single call to animateToCameraPosition to move the camera there.

I posted some code for calculating the centre and zoom level for a camera to fit a bounds here:

How to setRegion with google maps sdk for iOS?

So you could use something similar to calculate a camera position which would fit your markers to the screen.



Related Topics



Leave a reply



Submit