我想让我的谷歌地图地图视图只有一半的屏幕。我将地图视图的大小调整为屏幕的一半还修改了代码,只有地图视图的边界也就是屏幕的一半但它仍然是全屏。有人有解决办法吗?
// 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];
你可以在storyboard的帮助下完成。
-
在你的ViewController中拖拽一个UIView并添加GMSMapView类到UIView .
-
使用storyboard设置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);