Search code examples
google-mapsios6google-maps-sdk-ios

Google ios sdk mapview with storyboards


Can you advise if storyboards are supported with google maps ios sdk v 1.1. I'm getting some strange results

I have to 2 view controllers for maps. The first one displays a single map and renders absolutely fine as it pushed onto the navigationcontroller using storyboard push segue..

I have another map viewcontroller which is loading multiple markers. This view controller is also on the storyboard but loaded using a custom transition to fade in.

I am loading the views as per the sdk examples in the loadView method.

I have 3 problems with it

1.The first time the map with multiple markers is loaded the map does not get displayed/rendered. When i tap the button to display the view again (which does nothing if the view is loaded) it then renders the map and markers.

2.I close this view and load another view using the custom segue. if i go back to the map view with multiple markers i get an exception in the loadview method when it tries to assign the mapview to the view

  *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <GMSVectorMapViewBridge: 0x150376a0; frame = (0 0; 320 416); layer = <CALayer: 0x15055cd0>> is associated with <GMMapResultsViewController: 0x10faa2a0>. Clear this association before associating this view with <GMMapResultsViewController: 0xb51ad90>.

3.Lastly if i load the first map view controller with asingle marker, it loads fine, then I return to the 2nd map view controller with multiple markers. The same problem occurs when rendering the map. then if i try to select a map marker it is not handled by the delegate. Even though it would work ok if i loaded this map the first time.


Solution

  • I suspect if you do the following, your problem may go away...

    • add a UIView into the view controller where you're working
    • set it's type to be GMSMapView in the identity inspector.

    Then control-drag it to your code as you would for any other outlet.

    Once you've done this working with the Google maps becomes quite easy.