如何将 Google Map 放入自定义 UIView [英] How to put Google Map in a custom UIView

查看:26
本文介绍了如何将 Google Map 放入自定义 UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道之前已经问过这个问题,但没有一个答案对我来说真的很清楚,而且我在互联网上找不到好的教程......所以,我想把谷歌地图放在不同的 UIView 中主要是为了能够在顶部显示我的菜单栏.

I know this question has already been asked before, but none of the answers were really clear to me and I can't find good tutorial on Internet... So, I want to put Google maps in a different UIView from the principal one in order to be able to show my menu bar on top.

这是我的实际代码:

#import "MapViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@implementation MapViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:46.809885
                                                            longitude:-71.184556
                                                                 zoom:18];
    mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    self.view = mapView;
    mapView.mapType = kGMSTypeHybrid;

}

@end

实际上,地图遍布整个应用程序.它已经将我的 UIView 的类设置为 GMSKMapView 并创建了一个出口名称 mapView 以将我的 UIView 与控制器链接起来.

Actually, the map is all over the app. It already set the class of my UIView to GMSKMapView and made an outlet name mapView to link my UIView with the controller.

我使用 Xcode 4.6.2

I use Xcode 4.6.2

感谢您的帮助!

推荐答案

我正在使用此代码:

//头文件

@property (strong, nonatomic) IBOutlet UIView *viewForMap;
@property (nonatomic, strong) IBOutlet GMSMapView *mapView;
@property (nonatomic, strong) IBOutlet GMSCameraPosition *camera;

//实现文件

 self.camera = [GMSCameraPosition cameraWithLatitude:46.2220
                                          longitude:25.2330 zoom:5
                                            bearing:0
                                       viewingAngle:0
               ];

    self.mapView = [GMSMapView mapWithFrame:_viewForMap.bounds camera:_camera];
    self.mapView.delegate = self;

    [self.viewForMap addSubview:_mapView];

UPD

更改地图类型:

self.mapView.mapType = kGMSTypeHybrid; //kGMSTypeNormal kGMSTypeHybrid kGMSTypeSatellite kGMSTypeTerrain

再次更改相机视图:

_mapView.camera = [GMSCameraPosition cameraWithLatitude:newLat
                                                  longitude:newLong
                                                       zoom:1
                                                    bearing:0
                                               viewingAngle:0
                       ];

别忘了在头文件中添加:

don't forget to add in header file:

<GMSMapViewDelegate>

这篇关于如何将 Google Map 放入自定义 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆