0

我试图让我的谷歌地图地图视图只有屏幕的一半。我已将地图视图的大小调整为屏幕的一半,并且还更改了我的代码,因此它只是地图视图的边界,它是屏幕的一半,但它仍然是全屏的。有人有解决方案吗?

// 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;

谢谢,

柯蒂斯

4

2 回答 2

1

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

[self.view addSubview:_mapView];
于 2014-08-06T22:09:59.480 回答
0

你可以在故事板的帮助下做到这一点。

  • 在您的 ViewController 中拖动一个 UIView 并将 GMSMapView 类添加到 UIView。

  • 使用情节提要设置 UIView 的帧大小。为 UIView 创建插座(将其命名为 mapView)并连接它。

  • 在 viewDidLoad 下的 ViewController 类中添加这两行以查看谷歌地图。

            GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: YOUR_LATITUDE 
            longitude: YOUR_LONGITUDE zoom:8];
    
            [self.mapView setCamera:camera];
    
  • 使用以下代码将标记添加到位置。

    GMSMarker *marker = [[GMSMarker alloc]init];
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(YOUR_LATITUDE, YOUR_LONGITUDE);
    
于 2016-03-04T05:19:50.420 回答