ios - 为 ios 添加 google map sdk 后我看不到 map

标签 ios objective-c google-maps google-maps-sdk-ios

我想在 UIViewController 上方添加一个谷歌地图。但除了我定义的一些标记外,我什么也看不到。问题看起来像这样: enter image description here 这是相关代码:

- (void)viewDidLoad {
previousContext = [EAGLContext currentContext];
[super viewDidLoad];


GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                        longitude:151.2086
                                                             zoom:10];

mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 1136, 640) camera:camera];
//mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;
mapView_.delegate = self;
// Listen to the myLocation property of GMSMapView.
[mapView_ addObserver:self
           forKeyPath:@"myLocation"
              options:NSKeyValueObservingOptionNew
              context:NULL];

[EAGLContext setCurrentContext: previousContext];

//add makers
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(39.900285, 116.274020);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"aaa";
marker.snippet = @"population : 5";
marker.infoWindowAnchor = CGPointMake(0.5, 0.5);
marker.map = mapView_;
marker.icon = [UIImage imageNamed:@"tempmarker.png"];

CLLocationCoordinate2D position2 = CLLocationCoordinate2DMake(39.860285, 116.274020);
GMSMarker *marker2 = [GMSMarker markerWithPosition:position2];
marker2.title = @"bbb";
marker2.snippet = @"population : 5";
marker2.infoWindowAnchor = CGPointMake(0.5, 0.5);
marker2.map = mapView_;
marker2.icon = [UIImage imageNamed:@"tempmarker2.png"];



//add buttons:directRoom, rank, achievement, mission, home
....

[self.view insertSubview: mapView_ atIndex: 0];

[EAGLContext setCurrentContext:nil];
// Ask for My Location data after the map has already been added to the UI.
dispatch_async(dispatch_get_main_queue(), ^{
    mapView_.myLocationEnabled = YES;
});
}

那么,如何处理这个问题,非常感谢!

最佳答案

有关引用,请参阅来自 Google 的演示(复制在下方)。它与您发布的内容相似,但您可以尝试一些操作:

  1. 确保您的 API key 有效并且 API 可以获取图 block
  2. 检查您要插入的 map View 的 z-index 顺序:[self.view insertSubview: mapView_ atIndex: 0]; 插入在其他所有内容之后。尝试 [self.view addSubview:mapView_]

演示代码,来自 Google ( https://developers.google.com/maps/documentation/ios/ ):

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

@implementation DemoViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                          longitude:151.2086
                                                               zoom:6];
  GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

  GMSMarker *marker = [[GMSMarker alloc] init];
  marker.position = camera.target;
  marker.snippet = @"Hello World";
  marker.animated = YES;

  self.view = mapView;
}

@end

关于ios - 为 ios 添加 google map sdk 后我看不到 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19931664/

相关文章:

ios - 电影/GIF 背景 iOS 应用

ios - 从加载程序复制位图数据

android - 制作我的 Ionic AngularJS 程序的 iOS 应用程序

android - GooglePlayServicesUtil 错误对话框按钮不执行任何操作

c++ - 错误 : boost/scoped_ptr. hpp:使用 libkml 时没有这样的文件或目录

ios - ipad 和 iphone 的 MainWindow.xib

objective-c - 项目构建中的 CocoaPods 错误

ios - 如何在 UITableView 的编辑模式下启用滑动删除和删除按钮

objective-c - 不在 Objective-C 中使用 _Bool 的原因?

javascript - 谷歌地图在 IE7 中不工作