1
votes

I am trying to install Google Maps API to an app for iOS7. After following Google's guidelines and videos I ended up with the following error: [GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance 0x10b98e6c0

I am using Storyboard, and trying to make this map appears above a TableView in the same viewController.

In this app, I use Parse, which is fetching data to my TableView, and is working fine.

I tried to use a couple of suggestions which I found here on StackOverflow, but the problem persists:

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

Apparently the issue is related to this method:

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

When I erases it, the error goes away.

My TestViewController is coded as below(no table or anything, but still not working):

//  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

I also imported all frameworks, as recommended, and did put -ObjC into my otherLinkerFlags, without success.

In addition to that, I tested the process I am using in a new blank project and it worked fine, but, when I try to add a blank viewController just as a test to the original project, it does not work.

Another test I did, was to add a view to this blank viewController and try what is stated on StackOverflow's references I posted above.

Has anyone got any suggestions about what is happening?

Maybe a conflict with Parse's framework or some other library?

Instead of using -ObjC I also tried -force_load $(PROJECT_DIR)/GoogleMaps.framework/GoogleMaps and the error goes away, it asks me to allow my current position, but the screen does not load.

1
don't set the view in viewDidLoad! That is the job of loadView. So move the map view creation code to the loadView method.Felix
@phix23 Tried with loadView, but got the same error. In addition I tried to move it to viewWillLayoutSubviews method, the error disappears, but I got only a black view.Joao Paulo
Where are you putting the code that is causing the crash - i.e. [GMSMapView animateToCameraPosition:]?Adam
@Adam I tried both, viewDidLoad and loadView as phix23 suggested. Interesting that when I put -force_load $(PROJECT_DIR)/GoogleMaps.framework/GoogleMaps the crash goes away, it asks my current location, but it does not load my view. It keeps loading until gets a memory crash.Joao Paulo
Don't replace self.view with mapView_ - instead, add mapView_ as a subview to self.viewAdam

1 Answers

2
votes

What you have to do is to add -objC flag in your "project" build setting, instead of "target"'s build setting.

As it is mentioned in the following section from Google's Documentation

**" 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. "**

By this way, I was able solve Google Maps animateToCameraPosition issue.