4

我尝试使用 GoogleMapsSDKDemos 中的代码将地图视图调整为屏幕上较小的矩形,但它似乎没有任何效果。这是我的代码:

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 限制为一个小方块,但它仍然占据了整个屏幕。

4

2 回答 2

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:] 创建

于 2013-03-15T13:04:10.820 回答
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_];
于 2013-12-17T01:12:10.243 回答