2014-04-19 109 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問題。