我正在尝试按照指南here
在iOS中加载谷歌地图视图我为地图视图创建了一个名为iptechMapViewController.h的新viewController,iptechMapViewController.m和iptechMapViewController.xib
这是iptechMapViewController.m中的代码:
#import "iptechMapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface iptechMapViewController ()
{
GMSMapView *mapView_;
}
@end
@implementation iptechMapViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
然后在另一个名为iptechFlipsideViewController.m的视图控制器中,我试图按如下方式显示iptechMapViewController:
- (IBAction)showMap:(id)sender
{
iptechMapViewController *controller = [[iptechMapViewController alloc] initWithNibName:@"iptechMapViewController" bundle:nil];
[self.view addSubview:controller.view];
}
但是点击连接到IBAction showMap的showMap按钮后,iOS请求访问我的位置的权限警报出现后我触摸OK,之后没有任何显示,在控制台中我收到以下错误“
Failed to make complete framebuffer object 8cd6
由于
答案 0 :(得分:2)
将CGRectZero
传递给mapWithFrame
仅在地图视图是根视图控制器的根视图时才有效 - 在这种情况下,它会调整大小以适合屏幕。在您的情况下,由于地图是子视图,因此您需要在创建地图视图时指定大小。