【发布时间】:2014-04-19 13:48:05
【问题描述】:
我正在尝试将 Google Maps API 安装到适用于 iOS7 的应用中。在遵循 Google 的指南和视频后,我遇到了以下错误:[GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance 0x10b98e6c0
我正在使用 Storyboard,并试图使此地图出现在同一 viewController 中的 TableView 上方。
在这个应用程序中,我使用 Parse,它将数据提取到我的 TableView,并且工作正常。
我尝试使用我在 StackOverflow 上找到的几个建议,但问题仍然存在:
Cannot put a google maps GMSMapView in a subview of main main view?
How to set the frame for mapview - in google GMSMap for iOS6
显然问题与此方法有关:
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
当我删除它时,错误就消失了。
我的 TestViewController 编码如下(没有表格或任何东西,但仍然无法正常工作):
// TesteViewController.m
//
#import "TesteViewController.h"
#import <GoogleMaps/GoogleMaps.h>
#import "AppDelegate.h"
@interface TesteViewController ()
@end
@implementation TesteViewController{
GMSMapView *mapView_;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Create a GMSCameraPosition that tells the map to display the
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_;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我还按照建议导入了所有框架,并将-ObjC 放入我的otherLinkerFlags,但没有成功。
除此之外,我测试了我在一个新的空白项目中使用的过程,它运行良好,但是,当我尝试添加一个空白 viewController 只是作为对原始项目的测试时,它不起作用.
我做的另一个测试是在这个空白viewController 中添加一个视图,并尝试我在上面发布的 StackOverflow 参考中所述的内容。
有人对正在发生的事情有任何建议吗?
可能与 Parse 的框架或其他库发生冲突?
我没有使用-ObjC,而是尝试了-force_load $(PROJECT_DIR)/GoogleMaps.framework/GoogleMaps,错误消失了,它要求我允许我当前的位置,但屏幕没有加载。
【问题讨论】:
-
不要在 viewDidLoad 中设置视图!这就是 loadView 的工作。所以将地图视图创建代码移到loadView方法中。
-
@phix23 尝试使用 loadView,但得到了同样的错误。另外我尝试将它移动到 viewWillLayoutSubviews 方法,错误消失了,但我只有一个黑色的视图。
-
您将导致崩溃的代码放在哪里 - 即
[GMSMapView animateToCameraPosition:]? -
@Adam 我按照 phix23 的建议尝试了 viewDidLoad 和 loadView。有趣的是,当我输入
-force_load $(PROJECT_DIR)/GoogleMaps.framework/GoogleMaps时,崩溃消失了,它会询问我的当前位置,但不会加载我的视图。它会一直加载直到内存崩溃。 -
不要将
self.view替换为mapView_- 而是将mapView_作为子视图添加到self.view
标签: ios objective-c google-maps google-maps-sdk-ios