Search code examples
xcodegoogle-maps-sdk-ios

Google maps sdk - Map overlays evrything in my storyboard


So i am using xcode 6.2 and i am starting with making apps. but i have a question: whenever i drag something in my storyboard like a navigation bar the map overlays it, it simply won't show up, please help. Here is my code

#import "ViewController.h"

@interface ViewController () {
    GMSMapView *mapView;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:43.642510 longitude:-79.387038 zoom:12 bearing:0 viewingAngle:0];
    mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView.myLocationEnabled = YES;
    self.view = mapView;


    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(43.642510, -79.387038);
    marker.title = @"CN-Tower";
    marker.snippet = @"A beautifull tower";
    marker.map = mapView;
    marker.opacity = 0.7;
}

Thanks anyway, JP


Solution

  • When you do self.view = mapView you're setting the root view of the view controller to the map - and so the map covers everything, replacing whatever you designed in your storyboard.

    What you need to do is add the map as a subview of the root view, eg here's a few ways to do it:

    Using the Google Maps SDK in views other than the main view

    Google Maps iOS SDK - Add UIView/UIButton over a GMSMapView

    Google Maps iOS SDK and storyboards