2013-04-10 50 views
2

我正在嘗試在Google Map View中爲iOS6加載地點。 如何設置地圖的框架? 目前,它是全屏將Google地圖分配給子視圖時的黑屏

-(void)loadView { 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989 
                 longitude:76.316142 
                  zoom:15]; 
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    self.view = mapView_; 

    } 

我試圖用當前視圖中創建一個新的(小)查看並添加地圖內部的,但當時的頁面沒有得到loaded.It顯示全屏黑屏

-(void)loadView { 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989 
                 longitude:76.316142 
                  zoom:15]; 
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

    [self.view Addsubview:newView]; 
    self.newView = mapView_; 

    } 

回答

1

嘗試

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

[self.view addSubview:mapView_]; 
+0

我試過你提出的解決方案,但它仍然給黑屏。我有一個針對我添加名爲myView的UIView的'viewcontroller.h'文件的出口。我使用'self.view'以及'self.myView',但它似乎沒有工作。 – 2013-04-10 19:18:23

+0

看起來不錯..什麼是view.bounds返回的CGRect? – 2013-04-19 07:56:09

+0

(0,0,大小,寬度) – 2013-04-19 11:36:18

1

,如果你投入的loadView它不會有一個觀點..廈門國際銀行的甚至沒有加載中... 把它放在viewDidLoad中

,做

mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; 
[self.view addSubview:mapView_]; 
2

終於找到了解決辦法。 取出的loadView方法,並把下面的代碼在視圖中沒有加載方法:

-(void)viewDidLoad{ 
    [super viewDidLoad]; 

    // Do any additional setup after loading the view from its nib. 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                  longitude:151.20 
                   zoom:6]; 

    mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 100, 100) camera:camera]; 
    [self.view addSubview:mapView_]; 
    // Create a GMSCameraPosition that tells the map to display the 
    // coordinate -33.86,151.20 at zoom level 6. 

    mapView_.myLocationEnabled = YES; 

    // Creates a marker in the center of the map. 
    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
    marker.title = @"Sydney"; 
    marker.snippet = @"Australia"; 
    marker.map = mapView_; 
} 
1

檢查申報@property爲GMSMapView中,如果是弱屬性然後使它強。

@property(strong,nonatomic)GMSMapView * mapView;

+0

您的回答是我的一天。隊友的歡呼聲! – 2015-11-21 20:28:36

+0

享受哥們:);) – 2015-11-23 06:47:14