我试图使用GoogleMapsSDKDemos中的代码将mapview的大小调整为屏幕上的一个较小的矩形,但它似乎没有任何效果。这是我的代码:
mapView = [[GMSMapView alloc] initWithFrame:CGRectZero]; mapView.camera = [GMSCameraPosition cameraWithLatitude:38.98549782690282 经度:-76.94636067188021 变焦: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限制为一个小方块,但它仍占用整个屏幕。
答案 0 :(得分:3)
我会尝试这样的事情:
GMSCameraPosition* camera = [GMSCameraPosition
cameraWithLatitude: 38.98549782690282
longitude: -76.94636067188021
zoom: 17];
GMSMapView* mapView =
[GMSMapView mapWithFrame: GRectMake(0,0, 10, 25) camera: camera];
请注意GMSMapView
中GMSMapView.h
类的评论说:
这个类不应该直接实例化,而必须是 使用[GMSMapServices mapWithFrame:camera:]
创建
答案 1 :(得分:1)
尝试将地图添加到视图顶部:
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_];