7

My question is quite similar to this, except MKMapView. How can I do the same process(resize the map to fit all annotations/markers on screen at once) with Google Maps? As I understand I have to convert MKCoordinateRegion to GMSProjection, is my way right?

Community
  • 1
  • 1
hash3r
  • 411
  • 6
  • 16

1 Answers1

13

Thats very simple, just:

@property (nonatomic, strong) GMSMapView *mapView;

- (void)didTapFitBoundsWithMarkers:(NSArray *)markers
{
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init];;

for (GMSMarker *marker in markers) {
    bounds = [bounds includingCoordinate:marker.position];
}

GMSCameraUpdate *update = [GMSCameraUpdate fitBounds:bounds];
[self.mapView moveCamera:update];
[self.mapView animateToViewingAngle:50];
}
kokemomuke
  • 554
  • 7
  • 10
  • Thanks for your attention. When I posted question I couldn't find this method (`includingCoordinate`) in earler version of GMapsSDK. And API didn't include the `GMSCameraUpdate` class – hash3r Jun 25 '13 at 11:57