GoogleMaps basic iOS demo app crash - unrecognized selector sent to instance

前端 未结 9 1756
野趣味
野趣味 2020-11-30 12:45

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.

相关标签:
9条回答
  • 2020-11-30 13:16

    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"
      
    0 讨论(0)
  • 2020-11-30 13:17

    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.

    0 讨论(0)
  • 2020-11-30 13:19

    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

    0 讨论(0)
  • 2020-11-30 13:20

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

    if it helps someone

    0 讨论(0)
  • 2020-11-30 13:27

    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;
    }
    
    0 讨论(0)
  • 2020-11-30 13:29

    When you want to submit it to the store or test flight puts the flag -ObjC in the release too

    0 讨论(0)
提交回复
热议问题