Moving Google Maps Camera to a Location Moving Google Maps Camera to a Location swift swift

Moving Google Maps Camera to a Location


The GMSMapView class has the following function:

animate(to: GMSCameraPosition)

So in your code sample, instead of doing this:

mapView.camera = location

Try doing this:

mapView.animate(to: location)

Hope this helps!


in Swift3 and Swift4for moving marker to current position use this:

func myLocationBtnAction(_ sender: UIButton) {            mapView.moveCamera(GMSCameraUpdate.setTarget(CLLocationCoordinate2D(latitude: (mapView.myLocation?.coordinate.latitude)!, longitude: (mapView.myLocation?.coordinate.longitude)!), zoom: 16))

and for a specific location use this:

let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lng, zoom: 16)            mapView?.camera = camera            mapView?.animate(to: camera)

and don't forget to extend GMSAutocompleteViewControllerDelegate for current location


Swift 2.3

This code is used for my purpose. In which marker tap event used, which moves camera position of map. Hope you find your solution.

 func mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) -> Bool {        mapView.selectedMarker = marker        var point = mapView.projection.pointForCoordinate(marker.position)        let camera = mapView.projection.coordinateForPoint(point)        let position = GMSCameraUpdate.setTarget(camera)        mapView.animateWithCameraUpdate(position)        return true    }