4

I was expecting from that code, he will place all the markers on the map and zoom GMSMapView to fit all my GMSMarker, I use for this includingCoordinate method from class GMSCoordinateBounds, but it doesn't work as i want.

My example:

#import "ViewController.h"

@import GoogleMaps;
@import CoreLocation;

@interface ViewController ()

@property (weak, nonatomic) IBOutlet GMSMapView *mapView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSMutableArray <CLLocation *> *locations = [NSMutableArray array];
    [locations addObject:[[CLLocation alloc] initWithLatitude:55.755786 longitude:37.617633]];
    [locations addObject:[[CLLocation alloc] initWithLatitude:-22.9035393 longitude:-43.2095869]];
    [locations addObject:[[CLLocation alloc] initWithLatitude:51.50998 longitude:-0.1337]];

    NSArray *titles = @[@"marker1", @"marker2", @"marker3"];

    NSMutableArray <GMSMarker *> *markers = [NSMutableArray array];

    for (NSUInteger i = 0; i < 3; ++i)
    {
        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = locations[i].coordinate;
        marker.title = titles[i];
        marker.map = _mapView;
        [markers addObject:marker];
    }

    GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:markers[0].position coordinate:markers[0].position];

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

    [_mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

and this is the result of this code:

enter image description here

1 Answers1

0

From the image i think that this might be the maximum zoom out level available to the maps. If it so the screen will be the centre of your rectangular area which fits all marker. Try placing several marker close and see the bounds fits the all marker in your map, If you succeed in that then i m afraid you wont zoom out beyond this level.

Devang Tandel
  • 2,988
  • 1
  • 21
  • 43