The intend is to set the boundaries of the map to focus on all the markers.

ios Google Maps Scrren Shot 1

The ‘GMSMapView‘ class used to have a method ‘markers‘ which returned all the markers, but its now deprecated.
So, you will have to keep track of the markers added to the map.

Assuming that you have the following:

GMSMapView *mapView;
NSMutableArray *markers;

and all the markers are add to the NSMutableArray “markers”.

- (void)ShowAllMarkers
    CLLocationCoordinate2D firstLocation = ((GMSMarker *)markers.firstObject).position;
    GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:firstLocation coordinate:firstLocation];
    for (GMSMarker *marker in markers) {
        bounds = [bounds includingCoordinate:marker.position];
    [mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:50.0f]];

iOS Google Maps Screen Shot

Hope it helps. 🙂

Tagged with:  

Leave a Reply