如何在我的 ViewController 中设置 Google 地图应用程序的大小?

How do I set the size of Google Maps app within my ViewController?

我开始了一个全新的单一视图项目,其中只集成了 Google Maps SDK。

现在它横跨整个屏幕(全尺寸),我认为这是默认设置。我想减少它,这样它就不会占用顶部栏上的 space,我还想在按钮底部留下 space。我该怎么做?

这是在我的(单个)视图控制器中实现的唯一方法 class:

- (void)loadView {
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                        longitude:151.20
                                                             zoom:6];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
self.view = mapView;

// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView;
}
1)Add a UIView into the ViewController where you want and set your custom size
2)set it's type to be GMSMapView in IdentityInspector

.H 文件中的 delcare IBOutlet

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

.M

- (void)viewDidLoad {
    [super viewDidLoad];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
                                                                longitude:103.848
                                                                     zoom:12];
        self.map1.camera = camera;
        self.map1.delegate=self;
        self.map1.accessibilityElementsHidden = NO;
        self.map1.indoorEnabled = NO;
        self.map1.settings.myLocationButton = YES; 
        dispatch_async(dispatch_get_main_queue(), ^{
            self.map1.myLocationEnabled = YES;
        });
}

查看此博客http://vikrambahl.com/google-maps-ios-xcode-storyboards/

应该是这样的

GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectMake(0, 64, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height -200) camera:camera];

//底视图高度eg:200这里

要为视图控制器的有限部分添加 Google 地图,请按照以下步骤操作(使用故事板):

  1. 在现有 UIViewController 上添加 UIView
  2. 在客户 Class 中,添加 GMSMapView 作为客户 Class UIView

  3. 创建 UIView 的 IBOutlet 作为 mapView。

    @property (weak, nonatomic) IBOutlet GMSMapView *mapView;
    
  4. 给 mapView Height/Width 或约束。

  5. 您的函数将如下所示:

    - (void)loadView {
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
      GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                        longitude:151.20
                                                             zoom:6];
      self.mapView.myLocationEnabled = YES;
    
      // Creates a marker in the center of the map.
      GMSMarker *marker = [[GMSMarker alloc] init];
      marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
      marker.title = @"Sydney";
      marker.snippet = @"Australia";
      marker.map = self.mapView;
    }