Reputation: 746
I am working with Google maps in iOS. I wanted to animate my Camera such that it shows all the required Lat, Lngs. I am storing those locations in the array(as CLLocationCoordinate2D instances) and using GMSCoordinateBounds class to add these locations. This is my code:
let bounds = GMSCoordinateBounds()
bounds.includingCoordinate(firstLocation)
bounds.includingCoordinate(lastLocation)
let camUpdate = GMSCameraUpdate.fit(bounds, withPadding: 60)
mMapView.camera = GMSCameraPosition.camera(withLatitude: firstLocation.latitude, longitude: firstLocation.longitude, zoom: 18)
mMapView.animate(with: camUpdate)
firstLocation and lastLocation have correct values but the camera is not animating. Am I missing something?
Upvotes: 3
Views: 722
Reputation: 746
Very silly mistake. includingCoordinates function returns GMSCoordinateBounds object. I had to set to itself again for it to work like so:
bounds = bounds.includingCoordinate(firstLocation)
bounds = bounds.includingCoordinate(lastLocation)
If i set like above, it is working fine.
Upvotes: 10