I have the following code inside a UIViewController's viewDidLoad method. It is within a callback function that is called after fetching a list of places from a remote sever.
var bounds = GMSCoordinateBounds()
for place in self.placeCollection.places {
var position = CLLocationCoordinate2DMake(place.latitude, place.longitude)
bounds.includingCoordinate(position)
var marker = GMSMarker(position: position)
marker.title = place.title;
marker.map = self.mapView;
}
if self.placeCollection.places.count > 0 {
self.mapView.moveCamera(GMSCameraUpdate.fitBounds(bounds))
}
The map does not budge and is nowhere near any of the markers, I do not see any errors in the debug panel either. According to the docs this is the correct way to focus the map on a set of markers.
bounds.includingCoordinate
does not updatebounds
, instead it returns a newGMSCoordinateBounds
containing the new point.So, you need something like this: