How to fit bounds for coordinate array with google maps sdk for iOS? I need to zoom map for 4 visible markers.
Swift 5 version of Lirik's answer:
func focusMapToShowAllMarkers() {
if arrMarkers.count > 0 {
let firstLocation = (arrMarkers.first!).position
var bounds = GMSCoordinateBounds(coordinate: firstLocation, coordinate: firstLocation)
for marker in arrMarkers {
bounds = bounds.includingCoordinate(marker.position)
}
let update = GMSCameraUpdate.fit(bounds, withPadding: CGFloat(15))
self.mapView.animate(with: update)
}
}