【问题标题】:Zooming GMSMapView to fit GMSMarker markers?缩放 GMSMapView 以适合 GMSMarker 标记?
【发布时间】:2016-03-19 15:23:05
【问题描述】:

我期待该代码,他会将所有标记放在地图上并缩放 GMSMapView 以适合我所有的 GMSMarker,我用于 includingCoordinate 类中的 includingCoordinate 方法@ 987654327@,但它没有不能按我的意愿工作。

我的例子:

#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

这是这段代码的结果:

【问题讨论】:

标签: ios objective-c iphone google-maps cllocation


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 2016-11-04
    • 2013-05-26
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多