2013-03-09 35 views
4

我試圖使用GoogleMapsSDKDemos中的代碼將mapview的大小調整爲屏幕上的較小矩形,但它似乎沒有任何效果。這裏是我的代碼:調整Google Maps MapView iOS

mapView = [[GMSMapView alloc] initWithFrame:CGRectZero]; mapView.camera = [GMSCameraPosition cameraWithLatitude:38.98549782690282 longitude:-76.94636067188021 zoom:17];

self.view = [[UIView alloc] initWithFrame:CGRectZero]; 
mapView.autoresizingMask = 
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
mapView.frame = self.view.frame; 
mapView.clipsToBounds = YES; 
mapView.myLocationEnabled = YES; 
mapView.settings.tiltGestures = NO; 
mapView.settings.zoomGestures = NO; 

mapView.frame = CGRectMake(0,0, 10, 25); 

[self.view addSubview:self.mapView]; 

倒數第二行似乎應該將MapView限制爲一個小方塊,但它仍佔用整個屏幕。

回答

3

我會嘗試這樣的事:

GMSCameraPosition* camera = [GMSCameraPosition 
    cameraWithLatitude: 38.98549782690282 
    longitude: -76.94636067188021 
    zoom: 17]; 
GMSMapView* mapView = 
    [GMSMapView mapWithFrame: GRectMake(0,0, 10, 25) camera: camera]; 

注意,在GMSMapView.hGMSMapView類的評論說:

這個類不應直接instatiated,相反,它必須是 創建與[GMSMapServices mapWithFrame:camera:]

+0

我只是試過這個,它沒有工作,顯然我的GMSServices.h文件沒有它的mapWithFrame方法。我回去檢查API,如果你看[這裏](https://developers.google.com/maps/documentation/ios/map#add_a_map)它似乎使用GMMapView類?我不太確定,你說的話會有道理,但xcode無法在GMSServices中找到mapWithFrame方法(我也不能) – CSStudent 2013-03-15 18:25:15

+0

啊,是的,對不起,我是從標題中的評論開始,而不是從我自己的碼。你需要在'GMSMapView'上調用'mapWithFrame',而不是'GMSServices'(我猜這個頭部的註釋是不正確的)。我已經更新了我的代碼。 – 2013-03-15 23:23:12

+0

這對我來說似乎還不起作用,你自己試過了嗎?我有'smallMap = [GMSMapView mapWithFrame:CGRectMake(0,0,10,25)camera:camera];'smallmap是一個故事板中的GMMapView,它仍佔據整個屏幕。 – CSStudent 2013-03-16 03:16:05

1

試試這個添加地圖到p的觀點:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude 
                 longitude:longitude 
                  zoom:10]; 



mapView_ = [GMSMapView mapWithFrame:CGRectMake(0,0, width, height) camera:camera]; 
mapView_.delegate = self; 
mapView_.myLocationEnabled = YES; 
[self.view addSubview:mapView_];