定位GMSMapView以一次显示多个注释

has*_*h3r 6 google-maps ios

我的问题与非常相似,除了MKMapView. 如何使用Google地图执行相同的过程(调整地图大小以适应屏幕上的所有注释/标记)?据我所知,我必须将MKCoordinateRegion转换为GMSProjection,我的方法是对的吗?

kok*_*uke 13

这很简单,只是:

@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];
}
Run Code Online (Sandbox Code Playgroud)