0

I am trying to put a google maps view into a UIView in my app. The UIView was created inside a UIViewController in the stroryboard and I added I few auto layout constraints.

I am able to load the map inside the UIView based in the answer of this post: How to put Google Map in a custom UIView

However, when I load the view in (void)viewDidLoad method, it seems to completely ignore the constraints and maps get out the screen in some iPhones sizes (I could check this using Debug View Hierarchy). If I do not load the (void)viewDidLoad but instead, do this when the user press a button (ig.: IBAction), everything works perfectly.

I'm using exactly the same code in both situation. I've no ideia why the behaviour is different. Any help?

The code that I am using to load the maps into UIView:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
                                                        longitude:longitude                                                                 zoom:13];
mapView_ = [GMSMapView mapWithFrame:_mapsView.bounds camera:camera];
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;
[self.mapsView addSubview:mapView_];
Community
  • 1
  • 1
user3435595
  • 137
  • 1
  • 1
  • 9
  • change from `viewDidLoad` in `viewWillApear`; in `viewDidLoad` the constrains are not “ready” yet :) – TonyMkenu Feb 24 '15 at 07:09
  • Thank you for your replay, @TonyMkenu. I tried that but it is still with the same problem. – user3435595 Feb 24 '15 at 12:33
  • hmm.. you are using Autolayout.. it will not work with `addSubview`; try to change last line to `self.mapsView = mapView_; or.... here another example (with demo project) http://stackoverflow.com/a/26778538/1702413 – TonyMkenu Feb 24 '15 at 12:43
  • I found solution in here https://stackoverflow.com/questions/19177897/how-put-google-mapview-in-uiview kindly to take alook – Hariyadi andie Nov 13 '17 at 09:09

0 Answers0