アプリなどを開発するブログ

React Native / Swift / Ruby on Railsなどの学習メモ。


Google Maps iOS SDKで全てのマーカーが入るようにズームアウト

こんなかんじ

- (void)zoomMapToShowAllMarkers
{
    CLLocationCoordinate2D myLocation = ((GMSMarker *)_mapView.markers.firstObject).position;
    GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];

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

    [_mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:70.0f]];
}