Question

Im trying to run the basic iOS demo SDK code. I have created the API keyand it loads ok. Although i've transfered the code from viewDidLoad to loadView the effect remains. See the following code

-(void)loadView{
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    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;
}

The camera is created but when this line is executed

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

an NSException is thrown with the description -> -[GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance.

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance 0x14dbb870' * First throw call stack: (0x2f462f4b 0x39cd96af 0x2f4668e7 0x2f4651cb 0x2f3b44d8 0x4cebe9 0x4cd78f 0x4ccc41 0x4ccb3d 0x21ced5 0x31bda1bd 0x31bda139 0x1d4b27 0x1d4a83 0x1d51cd 0x31bda37b 0x31c850f1 0x31c85007 0x31c845e3 0x31c8430d 0x31c8407d 0x31c84015 0x31bd5da3 0x3185cc6b 0x3185847b 0x3185830d 0x31857d1f 0x31857b2f 0x31bce0c3 0x2f42e1cd 0x2f42bb71 0x2f42beb3 0x2f396c27 0x2f396a0b 0x34097283 0x31c3a049 0xf58b1 0x3a1e1ab7) libc++abi.dylib: terminating with uncaught exception of type NSException

Was it helpful?

Solution

I think you may have forgotten to make the class a GMSMapView delegate. The GMSMapViewDelegate bit after the () needs to be between <>

I don't assign that delegate as well as Googles Base Code does not assign it. I have fortunetly managed to get it working. The google documentation on Google Maps states what follows:

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.

But their example project, after my examination, has the flag set on target. Setting it on the build target within my project in my case helped and my posted code works fine.

OTHER TIPS

Add -ObjC in your project's GoTo: Click on your Project->Targets->Build Setting->search(Other Linker Flags) ->Set (-ObjC) Refer the Screenshot: Linker Flag

You most probably have forgotten to do this: (as stated in the google docs)

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.

I had the same error because I've mistakenly written -objC instead of -ObjC (with capital O)

if it helps someone

It's important to note that you should be adding the -ObjC to the Other Linker Flags section in your project.... NOT in your specific target.

Other people have mentioned 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.

However, it wasn't until I added the -ObjC flag into my projects 'Other Linker Flags' section, and NOT the targets 'Other Linker Flags' section, was I able to resolve the unrecognized selector error.

I think you may have forgotten to make the class a GMSMapView delegate. The GMSMapViewDelegate bit after the () needs to be between <>

@interface StructuredGeocoderViewController () GMSMapViewDelegate

@end

@implementation StructuredGeocoderViewController {
  GMSMapView *_mapView;
  GMSGeocoder *_geocoder;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                          longitude:151.2086
                                                               zoom:12];

  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  _mapView.delegate = self;

  _geocoder = [[GMSGeocoder alloc] init];

  self.view = _mapView;
}

When you want to submit it to the store or test flight puts the flag -ObjC in the release tooenter image description here

There is only few modification you have to do.

  1. Give the class name of the Custom UIView as "GMSMapView".
  2. Then make a outlet to your class.

    @IBOutlet var locationMapView: GMSMapView!

  3. In ViewDidLoad() add the following code.

    let camera = GMSCameraPosition.camera(withLatitude: 10.1518, longitude: 76.3930, zoom: 6.0)

    self.locationMapView.camera = camera
    
    let initialLocation = CLLocationCoordinate2DMake(10.1518, 76.3930)
     let marker = GMSMarker(position: initialLocation)
     marker.title = "Kochi"
     marker.snippet = "Kerala"
     marker.map = locationMapView
     marker.snippet = "Kerala"
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top