【问题标题】:Google Maps iOS [closed]谷歌地图 iOS [关闭]
【发布时间】:2013-03-24 08:34:32
【问题描述】:

我正在尝试将 Google 地图插入 iOS 中的 CGRect。但是下面的代码仍然在整个 iPhone 页面中显示地图。我该如何解决这个问题

CGRect rect = CGRectMake(50, 10, 200, 200);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
                                                        longitude:151.2086
                                                             zoom:6];
mapView_ = [GMSMapView mapWithFrame:rect camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
options.title = @"Sydney";
options.snippet = @"Australia";
[mapView_ addMarkerWithOptions:options];

【问题讨论】:

  • 我认为你应该使用 GMSMarkerOptions *options = [[GMSMarkerOptions alloc] initWithFrame:rect];
  • @ArpitKumar: GMSMarkerOptions 没有 initWithFrame 方法。
  • 投票关闭,因为过时了。 api改变了很多。这不再适用

标签: ios xcode ios6 maps google-maps-sdk-ios


【解决方案1】:

默认情况下,视图控制器的根视图会调整大小以填满屏幕。

您需要添加一个单独的视图作为根视图,然后将地图视图添加到其中。例如:

self.view = [[UIView alloc] initWithFrame: CGRectZero];
[self.view addSubview: mapView_];

【讨论】:

    【解决方案2】:

    我发现使用 Google Maps Views 的一个好方法是:

    1 - 将一个新的视图对象拖到你的控制器或视图上

    2 - 相应的大小和位置

    4 - 在身份检查器中将类设置为 GMSMapView

    5 - 使用助手控制拖动,将其作为属性提供给视图控制器

    6 - 让所有内容都与您在编辑器中指定的大小完全相同,并将其视为已初始化的地图视图!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 2016-04-06
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多