谷歌地图控件丢失

时间:2014-10-07 11:59:46

标签: ios google-maps uiview

我在故事板中添加了一个视图,然后将视图设置为GMSMapView。但现在缺少地图中的位置按钮和指南针。当我使用https://developers.google.com/maps/documentation/ios/start#adding_the_google_maps_sdk_for_ios_to_your_project中的说明以编程方式添加地图时,会显示地图控件。

.h class

@interface MapController : UIViewController{

    IBOutlet GMSMapView *mapView_;

}   

.m class

- (void)viewDidLoad {
    [super viewDidLoad];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:mapView_.myLocation.coordinate.latitude longitude:mapView_.myLocation.coordinate.longitude zoom:1];

    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

    mapView_.myLocationEnabled = YES;

    mapView_.settings.myLocationButton = YES;
    mapView_.settings.compassButton = YES;

}

2 个答案:

答案 0 :(得分:2)

这对我来说很好......

 mapView_ = [GMSMapView mapWithFrame:self.mapView.bounds
                                           camera:camera];

self.mapView是故事板中的视图。为该视图创建IBOutlet

答案 1 :(得分:0)

我在viewDidLoad中使用这些代码行并且它可以正常工作:

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.delegate = self;
self.view = mapView_;

mapView_.settings.myLocationButton = YES;
mapView_.settings.compassButton = YES;

此外,我不使用插座。它不需要。

相关问题