【问题标题】:Resizing Google Maps MapView iOS调整 Google Maps MapView iOS 的大小
【发布时间】:2013-02-25 06:04:50
【问题描述】:

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

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

【问题讨论】:

    标签: ios objective-c view resize google-maps-sdk-ios


    【解决方案1】:

    我会尝试这样的:

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

    请注意,GMSMapView.hGMSMapView 类的 cmets 说:

    这个类不应该直接实例化,而是必须 使用 [GMSMapServices mapWithFrame:camera:] 创建的

    【讨论】:

    • 我刚刚尝试过,但没有成功,显然我的 GMSServices.h 文件中没有该 mapWithFrame 方法。我回去检查了 API,如果你看 here 它似乎使用了 GMMapView 类?我不太确定,你说的有道理,但是 xcode 在 GMSServices 中找不到 mapWithFrame 方法(我也找不到)
    • 啊,是的,对不起,我是从标题中的评论开始的,而不是我自己的代码。您需要在GMSMapView 上调用mapWithFrame,而不是GMSServices(我猜标题中的注释不正确)。我已经更新了上面的代码。
    • 这似乎对我不起作用,您自己尝试过吗?我有smallMap = [GMSMapView mapWithFrame: CGRectMake(0,0, 10, 25) camera: camera];,其中 smallmap 是情节提要中的 GMMapView,它仍然占据整个屏幕。
    • 我以编程方式创建我的 UI,并将大小传递给 mapWithFrame 在那里工作。我还没有尝试过使用故事板或 xib。
    • 我通过使用包含整个视图控制器的容器视图解决了这个问题。我怀疑这是最有效的解决方案,但它确实有效。
    【解决方案2】:

    试试这个将地图添加到视图顶部:

    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_];
    

    【讨论】:

      猜你喜欢
      • 2012-06-13
      • 2015-08-23
      • 2012-08-15
      • 1970-01-01
      • 2018-06-15
      • 2013-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多