无法将google地图GMSMapView放在主要主视图的子视图中? [英] Cannot put a google maps GMSMapView in a subview of main main view?
问题描述
我正在努力解决这个问题!
我想将一个谷歌地图 GMSMapView
添加到 UIView
中,这只是主要部分 UIView
我的 ViewController
。
I'm struggling with this problem!
I want to add a google maps GMSMapView
into a UIView
that is only a portion of the main UIView
of my ViewController
.
应该很简单。 ..我在故事板上创建了一个 UIView
我想要的大小并把它放在主 UIView
中。
It should be simple... I created with the storyboard a UIView
of the size I want and put it in the main UIView
.
接口文件的片段:
@interface MapViewController : UIViewController <CLLocationManagerDelegate>
@property(nonatomic) IBOutlet GMSMapView *mapView;
将mapView链接到此 UIView
里面主 UIView
。
With the mapView linked with this UIView
inside the main UIView
.
我在实施中做了什么:
@synthesize mapView = _mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:10];
_mapView = [GMSMapView mapWithFrame:_mapView.bounds camera:camera];
_mapView.myLocationEnabled = YES;
}
这应该有效,不应该吗?
我得到的是我的内部UIView是空的。
This should work, shouldn't it? What I get is that my internal UIView is empty.
如果我按照google的开始指南实例化地图谷歌地图集成文档,它可以工作,但它将地图分配给MAIN UIView,这是另一回事。
If I instantiate a map following google's starting guide Google Map Integration Document, it works but it assigns the map to the MAIN UIView and thats a different thing.
我甚至尝试将故事板中mapView的类从 UIView
更改为 GMSMapView
。
地图显示在内部视图中,但它以奇怪的方式初始化
I tried even changing the class of my mapView in the storyboard from UIView
to GMSMapView
.
The map is showed in the inner view but it is initialized in a strange way making
- 系统抛出错误说
无法制作完整的帧缓冲区
"Failed to make complete frame buffer"
并减慢了视频的加载速度(在模拟器上需要2-3秒)
and slowing down a lot the loading of the view (it takes 2-3 seconds on the simulator)
- 地图在
viewDidLoad
方法中完成的任何相机更改都没有响应。
- The map not responding in any camera change done in the
viewDidLoad
method.
有任何建议吗?
我在StackOverflow上阅读了一些帖子,但找不到有效的解决方案:(
I read some posts here on StackOverflow but couldn't find a valid solution :(
推荐答案
根据其他答案,这里有三种实际工作方式。
Based on other answers, here are three ways that actually work.
- 在XIB上放置一个视图,并在XIB构建器中将其类更改为GMSMapView。请参阅下面的* map1。或者......
- 将其全部编码。将地图添加为子视图主视图。请参阅下面的* map2。或者......
- 添加地图a是XIB中已有出口的另一个子视图的子视图。 * map3如下。
.h
@interface GPViewController : UIViewController
@property (strong, nonatomic) IBOutlet GMSMapView *map1;
@property (strong, nonatomic) IBOutlet UIView *plainViewOnXIBHoldsMap3;
@end
.m
- (void)viewDidLoad{
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.0
longitude:151.20
zoom:6];
/* Option 1. view on XIB is class GSMMapView */
self.map1.camera = camera;
/* Option 2. add a map as a subview */
GMSMapView *map2 = [GMSMapView mapWithFrame:CGRectMake(0, 0, 100, 100) camera:camera];
[self.view addSubview:map2];
/* Option 3. add a map to a subview already on the XIB */
GMSMapView *map3 = [GMSMapView mapWithFrame:self.plainViewOnXIBHoldsMap3.bounds camera:camera];
[self.plainViewOnXIBHoldsMap addSubview:map3];
}
这篇关于无法将google地图GMSMapView放在主要主视图的子视图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!