Ios 缩放GMSMapView以适应GMSMarker标记?

Ios 缩放GMSMapView以适应GMSMarker标记?,ios,objective-c,iphone,google-maps,cllocation,Ios,Objective C,Iphone,Google Maps,Cllocation,我期望从该代码中,他将在地图上放置所有标记并缩放GMSMapView,以适合我所有的GMSMarker,我使用classgmscoordinatedbounds中的包括坐标方法,但它不能按照我的要求工作 我的例子是: #import "ViewController.h" @import GoogleMaps; @import CoreLocation; @interface ViewController () @property (weak, nonatomic) IBOutlet GMS

我期望从该代码中,他将在地图上放置所有标记并缩放
GMSMapView
,以适合我所有的
GMSMarker
,我使用class
gmscoordinatedbounds
中的
包括坐标
方法,但它不能按照我的要求工作

我的例子是:

#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
#导入“ViewController.h”
@导入谷歌地图;
@进口货位;
@界面视图控制器()
@属性(弱、非原子)IBMOutlet GMSMapView*mapView;
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
NSMutableArray*位置=[NSMutableArray];
[位置添加对象:[[CLLocation alloc]initWithLatitude:55.755786经度:37.617633];
[位置添加对象:[[CLLocation alloc]INITWITH纬度:-22.9035393经度:-43.2095869];
[位置添加对象:[[CLLocation alloc]initWithLatitude:51.50998经度:-0.1337];
NSArray*标题=@[@“marker1”、“marker2”、“marker3”];
NSMutableArray*标记=[NSMutableArray];
对于(整数i=0;i<3;++i)
{
GMSMarker*标记=[[GMSMarker alloc]init];
marker.position=位置[i]。坐标;
marker.title=标题[i];
marker.map=\u mapView;
[标记添加对象:标记];
}
GMSCoordinateBounds*bounds=[[GMSCoordinateBounds alloc]initWithCoordinate:标记[0]。位置坐标:标记[0]。位置];
用于(GMSMarker*标记中的标记)
{
边界=[边界包括坐标:marker.position];
}
[_MapViewAnimateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds];
}
-(无效)未收到记忆警告
{
[超级记忆警告];
}
@结束
这是这个代码的结果:


从图像中,我认为这可能是地图可用的最大缩小级别。 如果是这样,屏幕将是矩形区域的中心,适合所有标记。
试着把几个标记放在附近,看看边界是否适合你地图上的所有标记,如果你成功了,那么我恐怕你不会缩小到这个级别以外。

这可能会有帮助@Krupanshu我用的是谷歌地图,而不是MapKit