How to fit bounds for coordinate array with google maps sdk for iOS? I need to zoom map for 4 visible markers.
We can simplify this quite a bit, with code such as the following:
extension Array where Element: GMSMarker {
func encompassingCoordinateBounds() -> GMSCoordinateBounds {
reduce(GMSCoordinateBounds(), { $0.includingCoordinate($1.position) })
}
}
The call site would like:
let markers = [GMSMarker]()
let encompassingCoordinateBounds = markers.encompassingCoordinateBounds()