Google map does not fit in SubView properly

Viewed 559

I am using Google map but it's not set properly in subView. I am using swift 3.

@IBOutlet weak var mapSubView: UIView!
 var mapView:GMSMapView!
var placesClient: GMSPlacesClient!

I have used the following code in viewDidLoad:

let camera = GMSCameraPosition.camera(withLatitude: 28.616536, longitude: 77.379552, zoom: 12.0)
mapView = GMSMapView.map(withFrame: mapSubView.bounds, camera: camera)
mapSubView.addSubview(mapView)
mapView.delegate = self
self.drawPath()
placesClient = GMSPlacesClient.shared()

Screenshot from my simulator:

You have see white space in right side near google map

And a screenshot from my storyboard:

enter image description here

1 Answers

In viewDidLoad, your view is not completely rendered so the line

mapView = GMSMapView.map(withFrame: mapSubView.bounds, camera: camera)

will set the size of the mapView based on the bounds at that particular time. There are a couple of work arounds. One is to render your mapView at a later time e.g. in viewWillAppear. The other is to create a UIView in storyboard, set it's constraints, make it's class to be GMSMapView and connect an @IBOutlet. Also, you can fix it by using autoresizingMask

Related