2014-04-19 44 views
1

我正在尝试将Google Maps API安装到适用于iOS7的应用程序。在遵循Google的准则和视频后,我结束了以下错误:[GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance 0x10b98e6c0Google Maps animateToCameraPosition iOS7问题

我正在使用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]; 

当我删除它时,错误g远离。

我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和错误消失,它要求我允许我的当前位置,但屏幕无法加载。

+0

不要在viewDidLoad中设置视图!这是loadView的工作。因此,将地图视图创建代码移动到loadView方法。 – Felix

+0

@ phix23尝试loadView,但得到了同样的错误。另外,我试图将其移至viewWillLayoutSubviews方法,错误消失,但我只得到一个黑色的视图。 –

+0

你在哪里放置导致崩溃的代码 - 即'[GMSMapView animateToCameraPosition:]'? – Adam

回答

2

你需要做的是在你的“项目”构建设置中添加-objC标志,而不是“目标”的构建设置。

因为它是在下面的部分,从谷歌的文档

**" Choose your project, rather than a specific target, and open the 
    Build Settings tab. In the Other Linker Flags section, add -ObjC. If 
    these settings are not visible, change the filter in the Build 
    Settings bar from Basic to All. "** 

通过这种方式提到,我能够解决谷歌地图animateToCameraPosition问题。