如何将谷歌地图放入自定义的UIView中 [英] How to put Google Map in a custom UIView

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

问题描述

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

这是我的实际代码:

  #importMapViewController.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
code
$ b实际上,地图遍布应用程序。它已经将我的UIView的类设置为GMSKMapView,并创建了一个名称为mapView的链接,以将我的UIView与控制器链接。



我使用Xcode 4.6.2



感谢您的帮助!

解决方案

p>

//头文件

  @property(strong,nonatomic)IBOutlet UIView * viewForMap; 
@property(nonatomic,strong)IBOutlet GMSMapView * mapView;
@property(非原子,强大)IBOutlet GMSCameraPosition *相机;

//执行文件

  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
];

不要忘记添加到头文件中:

 < GMSMapViewDelegate> 


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.

Here is my actual code :

#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

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.

I use Xcode 4.6.2

Thank you for your help!

解决方案

I'm using this code:

//header file

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

//implementation file

 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

to change map type:

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

to change again camera view:

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

don't forget to add in header file:

<GMSMapViewDelegate>

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

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