Search code examples
iosobjective-cgoogle-mapsmapboxgoogle-maps-sdk-ios

ViewController not showing on Google Map didTapMarker method - iOS


I have a DetailViewController that is to be shown when user taps a marker on the mapView_. Initially I load the VC and set it hidden, and when the user would tap a marker, I would load values in the VC and show it. But it is not happening. Here's my code.

@property (strong, nonatomic) GMSMapView *mapView;

- (void)viewDidLoad 
{
    [super viewDidLoad];

    _whisperDetailView.hidden = YES;

    [_whisperDetailView initlize];
    _whisperDetailView.viewController = self;

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    self.view = mapView_;
}



- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{

    _detailView.whisper = marker.userData;
    _detailView.hidden = NO;

    return YES;
}

Storyboard snapshot:Storyboard

Funny thing is I was using Mapbox before and was doing exact same thing in its didSelectAnnotation function and everything was working great. I recently had to switch to Google Map and now its not working.

Any help is appreciated. Thanks.


Solution

  • Okay I've got it working now! Posting the answer for anyone else stuck in same situation:

    I changed the way I was adding my mapView_. instead of assigning self.view = mapView in viewDidLoad, I inserted mapView as a subview to my main view, like this:

    mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) camera:camera];
    [self.view insertSubview:mapView_ atIndex:0];
    

    And alas! everything works like a charm now! When I tap a marker, my DetailViewController shows with proper sizes and as I set it up in storyboard.