在主视图以外的视图中使用Google Maps SDK [英] Using the Google Maps SDK in views other than the main view
问题描述
我正在尝试在故事板中创建的主视图的子视图中使用iOS版Google Maps SDK,并通过IBOutlet(我将其称为UIView的子类,称为ExtraView)链接到视图控制器.当我按照SDK入门指南中的步骤进行操作时,SDK可以正常工作,但是它使用了层次结构中最不需要的视图(主视图),这是我所不希望的.我希望地图位于屏幕的较小部分,并将屏幕的其余部分用于其他内容.当我尝试将mapView_对象(请参阅入门指南)分配给self.extraView而不是self.view时,整个屏幕都是黑色的,并且在控制台输出中出现错误:
I am trying to use the Google Maps SDK for iOS in a subview of the main view which I created in the storyboard and linked to the view controller via an IBOutlet (I called it extraView, subclassed from UIView). When I follow the steps in the SDK getting started guide, the SDK works just fine, but it uses the uppermost view in the hierarchy (the main view), which I don't want. I want my map to be in a smaller portion of the screen and use the rest of the screen for something else. When I attempt to assign the mapView_ object (see the getting started guide) to self.extraView instead of self.view, the whole screen is black and I get an error in the console output:
应用程序窗口应在应用程序启动结束时具有根视图控制器"
"Application windows are expected to have a root view controller at the end of application launch"
还有其他人知道吗?我在文档中找不到任何内容,并且Google提供的示例代码未使用情节提要.
Has anyone else figured this out? I can't find anything in the documentation and the sample code Google provides does not use a storyboard.
推荐答案
这是...
- 将UIView添加到您正在工作的视图控制器中
- 在身份检查器中将其类设置为
GMSMapView
.
然后像其他任何出口一样,将其拖动到代码中.
Then control-drag it to your code as you would for any other outlet.
您可以在其设置器中惰性地实例化它...
You can lazily instantiate it in its setter...
- (void) setMapView:(GMSMapView *)mapView {
if (!mapView) {
mapView = [[GMSMapView alloc] initWithFrame:mapView.bounds];
}
_mapView = mapView;
}
要显示地图,Google的示例代码将变为...
To display a map Google's sample code becomes...
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
longitude:103.848
zoom:12];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
这篇关于在主视图以外的视图中使用Google Maps SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!