I'm struggling with this problem! I want to add a google maps GMSMapView
into a UIView
that is only a portion of the main UIView
of my ViewController
.
It should be simple... I created with the storyboard a UIView
of the size I want and put it in the main UIView
.
Snippet from Interface file:
@interface MapViewController : UIViewController <CLLocationManagerDelegate> @property(nonatomic) IBOutlet GMSMapView *mapView;
With the mapView linked with this UIView
inside the main UIView
.
What I do in the implementation:
@synthesize mapView = _mapView; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683 longitude:151.2086 zoom:10]; _mapView = [GMSMapView mapWithFrame:_mapView.bounds camera:camera]; _mapView.myLocationEnabled = YES; }
This should work, shouldn't it? What I get is that my internal UIView is empty.
If I instantiate a map following google's starting guide Google Map Integration Document, it works but it assigns the map to the MAIN UIView and thats a different thing.
I tried even changing the class of my mapView in the storyboard from UIView
to GMSMapView
. The map is showed in the inner view but it is initialized in a strange way making
"Failed to make complete frame buffer"
and slowing down a lot the loading of the view (it takes 2-3 seconds on the simulator)
viewDidLoad
method.Any suggestions?
I read some posts here on StackOverflow but couldn't find a valid solution :(
Based on other answers, here are three ways that actually work.
.h
@interface GPViewController : UIViewController @property (strong, nonatomic) IBOutlet GMSMapView *map1; @property (strong, nonatomic) IBOutlet UIView *plainViewOnXIBHoldsMap3; @end
.m
- (void)viewDidLoad{ [super viewDidLoad]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.0 longitude:151.20 zoom:6]; /* Option 1. view on XIB is class GSMMapView */ self.map1.camera = camera; /* Option 2. add a map as a subview */ GMSMapView *map2 = [GMSMapView mapWithFrame:CGRectMake(0, 0, 100, 100) camera:camera]; [self.view addSubview:map2]; /* Option 3. add a map to a subview already on the XIB */ GMSMapView *map3 = [GMSMapView mapWithFrame:self.plainViewOnXIBHoldsMap3.bounds camera:camera]; [self.plainViewOnXIBHoldsMap addSubview:map3]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With