繁体   English   中英

iOS Objective-C Google 地图仅在添加到子视图时在调试时显示

[英]iOS Objective-C Google map shows only on debug when added to a subview

我正在使用谷歌地图 SDK,首先一切正常,但它显示为全屏。 将地图添加到子视图后,地图不再显示。 我在 IBAction 上添加了一个断点并注意到通过后:

self.mapView1 = [GMSMapView mapWithFrame:_subview.bounds camera:camera];

地图在子视图中完美显示。

这就是我在 IBAction 中的代码:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.67 longitude:35.55 zoom:12];

self.mapView1 = [GMSMapView mapWithFrame:_subview.bounds camera:camera];

self.mapView1.myLocationEnabled = YES;
[_mapView1 setMinZoom:12 maxZoom:20];
self.mapView1.mapType = kGMSTypeSatellite;
self.mapView1.settings.compassButton = YES;
_mapView1.delegate = self;
[_mapView1 animateToViewingAngle:45];

// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(33.67, 35.55);
marker.title = @"City";
marker.snippet = @"Country";
marker.map = _mapView1;
[_subview addSubview:_mapView1];

这就是我想要的样子

提前致谢。

试试这个它对我有用。

GMSMapView *customView = [[GMSMapView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.67 longitude:35.55 zoom:12];

customView = [GMSMapView mapWithFrame:customView.bounds camera:camera];

customView.myLocationEnabled = YES;
[customView setMinZoom:12 maxZoom:20];
customView.mapType = kGMSTypeSatellite;
customView.delegate = self;
[customView animateToViewingAngle:45];

// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(33.67, 35.55);
marker.title = @"City";
marker.snippet = @"Country";
marker.map = customView;
[self.view addSubview:customView];

或者

GMSMapView *customView = [[GMSMapView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.67 longitude:35.55 zoom:12];
_mapView = [GMSMapView mapWithFrame:customView.bounds camera:camera];

_mapView.myLocationEnabled = YES;
[_mapView setMinZoom:12 maxZoom:20];
_mapView.mapType = kGMSTypeSatellite;
_mapView.settings.compassButton = YES;
_mapView.delegate = self;
[_mapView animateToViewingAngle:45];

// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(33.67, 35.55);
marker.title = @"City";
marker.snippet = @"Country";
marker.map = _mapView;
[customView addSubview:_mapView];
[self.view addSubview:customView];

还要检查您的 _subview 是否隐藏。

由于我无法发表评论,我将使用这种方式请您做一些事情:

1- 向这一行添加一个断点并检查 _subview.bounds 值。

self.mapView1 = [GMSMapView mapWithFrame:_subview.bounds camera:camera];

2- 在模拟器中运行时,单击Debug > View Debugging > Capture View Hierarchy并找到您的 AVPlayer,检查右侧面板上的属性。

创建 GMSMapView 时检查 _subview.bounds。

根据完成的时间,它可能不会被设置,你可能会得到一个 CGRectZero 框架。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM