Mahin Ibrahim Mahin Ibrahim - 1 month ago 17
Swift Question

AutoLayout in GMSMapView

I need GMSMapView in a particular view. Here viewForGMSMapView is my UIView. I used the below code.

let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 6.0)
let mapView = GMSMapView.mapWithFrame(viewForGMSMapView.bounds, camera: camera)

mapView.translatesAutoresizingMaskIntoConstraints = true;


mapView.myLocationEnabled = true
viewForGMSMapView.addSubview(mapView)


It helps to fix in my view. But when device screensize increases it fails. How to autolayout this GMSMapView. I need it to fit in my View

Answer

If you want translatesAutoresizingMaskIntoConstraints to be true, you need to set an appropriate autoresizingMask so it resizes or shrinks correctly.

Try:

mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

Otherwise, you need to set translatesAutoresizingMaskIntoConstraints to false and set up constraints for the map view.