GMSMapView animateToCameraPosition zoom in - zoom out animation

前端 未结 2 818
-上瘾入骨i
-上瘾入骨i 2021-01-12 08:08

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 movem

2条回答
  •  滥情空心
    2021-01-12 08:54

    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.

提交回复
热议问题