【问题标题】:Google Maps in MKMapView-type objectMKMapView 类型对象中的谷歌地图
【发布时间】:2014-05-29 23:58:00
【问题描述】:

按照此处https://developers.google.com/maps/documentation/ios/starthttps://developers.google.com/maps/documentation/ios/start“入门”页面上的说明,我在我的应用中使用了 Google 地图。

让您启动并运行的代码示例(发布框架和 API 密钥等)如下所示。

我的问题是,作为一个 Xcode 菜鸟,我想知道如何将地图限制在我的视图控制器上的一个对象中,比如在 MKMapView 中。

我假设这条线

@implementation YourViewController {
  GMSMapView *mapView_;
}

这段代码是以编程方式在整个视图控制器上创建地图的方式吗?

我怎样才能把它放在像 MKMapView 这样的东西中?

#import "YourViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@implementation YourViewController {
  GMSMapView *mapView_;
}

- (void)viewDidLoad {
  // Create a GMSCameraPosition that tells the map to display the
  // coordinate -33.86,151.20 at zoom level 6.
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                          longitude:151.20
                                                               zoom:6];
  mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  mapView_.myLocationEnabled = YES;
  self.view = mapView_;

  // Creates a marker in the center of the map.
  GMSMarker *marker = [[GMSMarker alloc] init];
  marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
  marker.title = @"Sydney";
  marker.snippet = @"Australia";
  marker.map = mapView_;
}

@end

【问题讨论】:

  • 您的问题到底是什么?目前的措辞尚不清楚。有什么事情没有按您的预期工作吗?如果不是,那是什么?
  • 你的意思是作为一个不占据整个视图控制器视图的子视图?

标签: ios google-maps-sdk-ios


【解决方案1】:

这是使地图占据整个视图的行,即根视图只是地图:

self.view = mapView_;

不要这样做,而是创建一些其他视图,然后将地图视图添加到其中。这取决于您是手动创建视图,还是使用 xib/storyboard。

[otherView addSubview: mapView_];

您还需要更改此行:

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

仅当地图视图是根视图时,将框架设置为 CGRectZero 将调整地图的大小以填充屏幕。相反,您需要指定所需框架的大小。

【讨论】:

  • 当我在我的视图控制器上实现上述视图代码时会出现黑屏。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-27
  • 2014-09-02
  • 2011-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-17
相关资源
最近更新 更多