我正在尝试使我的Google Maps地图视图仅占屏幕的一半。我已将地图视图的大小调整为屏幕的一半,并更改了代码,因此仅地图视图的边界即屏幕的一半,但它仍变为全屏。任何人都有解决方案吗?

// setting up mapView
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    _mapView = [GMSMapView mapWithFrame:_mapView.bounds 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;

    // Creates a marker in the center of the map.
    GMSMarker *marker2 = [[GMSMarker alloc] init];
    marker2.position = CLLocationCoordinate2DMake(-36.86, 151.20);
    marker2.title = @"Sydney2";
    marker2.snippet = @"Australia2";
    marker2.map = _mapView;


谢谢,

柯蒂斯

最佳答案

您可以尝试将_mapView添加为子视图,而不是将其分配给self.view。

[self.view addSubview:_mapView];

07-24 16:01