我試圖使用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限制爲一個小方塊,但它仍佔用整個屏幕。
我只是試過這個,它沒有工作,顯然我的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
啊,是的,對不起,我是從標題中的評論開始,而不是從我自己的碼。你需要在'GMSMapView'上調用'mapWithFrame',而不是'GMSServices'(我猜這個頭部的註釋是不正確的)。我已經更新了我的代碼。 – 2013-03-15 23:23:12
這對我來說似乎還不起作用,你自己試過了嗎?我有'smallMap = [GMSMapView mapWithFrame:CGRectMake(0,0,10,25)camera:camera];'smallmap是一個故事板中的GMMapView,它仍佔據整個屏幕。 – CSStudent 2013-03-16 03:16:05