2014-10-07 58 views
0

我在故事板中添加了一个视图,然后将视图设置为GMSMapView。但是现在地图中的位置按钮和指南针缺失。当我使用来自https://developers.google.com/maps/documentation/ios/start#adding_the_google_maps_sdk_for_ios_to_your_project的指令以编程方式添加地图时,地图控件出现。谷歌地图控制丢失

.H类

@interface MapController : UIViewController{ 

    IBOutlet GMSMapView *mapView_; 

} 

.M类

- (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

这工作得很好,我...

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

self.mapView是在故事板视图。该视图

+0

你为什么需要自我。 – 2014-10-07 12:13:07

+0

哦,太棒了我非常感谢你! @SarathNeeravallil – 2014-10-07 12:15:09

0

我使用的代码中viewDidLoad中这些行创建IBOutlet中,它正常工作:

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

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

此外,我不使用不必要的outlet.It。