Google Maps iOS SDK -在GMSMapView上添加UIView/UIButton



我正在开发带有storyboard的Google Maps iOS SDK的iOS应用程序。在我的主视图控制器"viewDidLoad"我已经实现了GMSMapView和显示它的

self.view = mapView_;

一切都很顺利。现在我想在地图上添加一个UIView或UIButton,比如myLocation按钮样式。有没有办法添加它,并通过故事板使用它?我已经通过代码在地图上覆盖了对象,但我真的需要自动布局,所以通过Storyboard管理它会很好。谢谢。

试试这个确保将mapView框架设置为与CGRectZero不同的值(它适用于self)。视图只= mapView):

mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
[self.view insertSubview:mapView atIndex:0];

正如Saxon所说,在索引0处插入视图将把其他对象放在前面。

实际上,这是我在尝试了所有的方法后唯一有效的方法

[self.view insertSubview:self.yourUIImageview aboveSubview:self.mapView]

祝你好运

你想有一个位置按钮与自己的自定义图像吗?还是别的什么?你试过:mapview_.settings.myLocationButton = YES;吗你能说得更具体一点吗?我也在用GM的iOS SDK,也许我能帮到你。

你可以尝试这样做:

[self.view insertSubview: mapView_ atIndex: 0];

这将插入映射作为根视图的子视图(而不是替换根视图),留下你的其他视图(如按钮等)。在索引0处插入它将使它位于其他视图的下面。

添加你的地图作为子视图

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitudeoom:6];
mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];[self.view insertSubview:mapView atIndex:0];

现在你可以拖放你的任何你的UIcontrol按钮,文本域,它将在mapview上可见,或者你也可以像上面一样添加子视图。

最新更新