谷歌地图iOS MapView

时间:2014-08-06 18:25:07

标签: ios google-maps gmsmapview

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

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

谢谢,

柯蒂斯

2 个答案:

答案 0 :(得分:1)

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

[self.view addSubview:_mapView];

答案 1 :(得分: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);