2

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

这是我的实际代码:

#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 与控制器链接起来。

我使用 Xcode 4.6.2

谢谢您的帮助!

4

2 回答 2

5

我正在使用这段代码:

//头文件

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

不要忘记添加头文件:

<GMSMapViewDelegate>
于 2013-06-13T12:06:25.183 回答
1

首先创建 UIView 的 outlet

#import <GoogleMapsM4B/GoogleMaps.h>
@interface ViewController : UIViewController<GMSMapViewDelegate>
@property (strong, nonatomic) IBOutlet GMSMapView *mapView;

在 .h 文件中添加这个

现在在视图 didload 方法中将其添加到 .m 文件中

self.mapView.myLocationEnabled = YES;
self.mapView.mapType = kGMSTypeNormal;
self.mapView.settings.compassButton = YES;
self.mapView.settings.myLocationButton = YES;
self.mapView.delegate = self;
于 2015-09-26T06:34:35.133 回答