Eugene Gordin
Eugene Gordin

Reputation: 4107

Determine proper zoom level on GMSMapView to fit all the locations needed?

In my iOS app I'm using GoogleMaps and APIs for maps and I'm not very familiar with it.

I know that with iOS native MKMapView you can set a visible map rect to fit all the points needed at a proper zoom level, like described here: Zooming MKMapView to fit annotation pins?

but I'm not sure how to do such thing for GMSMapView. Does anyone know how to do it?

Any kind of help is highly appreciated!

Upvotes: 1

Views: 512

Answers (1)

RTXGamer
RTXGamer

Reputation: 3712

Add this after setting up markers on the Map:

var bounds = GMSCoordinateBounds()
for coordinate in testCoordinates {
    bounds = bounds.includingCoordinate(coordinate)
}
let update = GMSCameraUpdate.fit(bounds, withPadding: 50)
mapView.animate(with: update)

Upvotes: 2

Related Questions