Search code examples
iosswiftgoogle-mapsnslayoutconstraintgoogle-maps-sdk-ios

GMSMapView not showing anything if constraints are added from the Storyboard


I have a UIView inside a UIScrollView. I have given it the custom GMSMapView class. I need this view nestled between two other views.

I am using Swift 5, Xcode 11.3 and GoogleMaps (3.7.0)

The map shows up normally if I do not add any constraints to the UIView.

However as soon as I add constraints to the view the map stops displaying anything. The constraints I am adding are leading and trailing to the UIScrollView and vertical spacing to the top and bottom views.

I have tried mapView.layoutIfNeeded() in viewDidLoad() as suggested in an answer here. But nothing seems to work.

enter image description here


Solution

  • You need to

    1-Set a height constraint to the mapView

    2-Inner top view width = main vc's view width

    3-Hook all views properly from top to down inside the scrollView