5

I am trying to use the Google Maps SDK for iOS in a subview of the main view which I created in the storyboard and linked to the view controller via an IBOutlet (I called it extraView, subclassed from UIView). When I follow the steps in the SDK getting started guide, the SDK works just fine, but it uses the uppermost view in the hierarchy (the main view), which I don't want. I want my map to be in a smaller portion of the screen and use the rest of the screen for something else. When I attempt to assign the mapView_ object (see the getting started guide) to self.extraView instead of self.view, the whole screen is black and I get an error in the console output:

"Application windows are expected to have a root view controller at the end of application launch"

Has anyone else figured this out? I can't find anything in the documentation and the sample code Google provides does not use a storyboard.

user2105505
  • 686
  • 1
  • 9
  • 18

2 Answers2

13

Here's how...

  • add a UIView into the view controller where you're working
  • set it's class to be GMSMapView in the identity inspector.

Then control-drag it to your code as you would for any other outlet.

You can lazily instantiate it in its setter...

- (void) setMapView:(GMSMapView *)mapView {
    if (!mapView) {
        mapView = [[GMSMapView alloc] initWithFrame:mapView.bounds];
    }
    _mapView = mapView;
}

To display a map Google's sample code becomes...

  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
                                                          longitude:103.848
                                                               zoom:12];
  self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
sberley
  • 2,238
  • 1
  • 16
  • 12
  • Thanks for your prompt response. Unfortunately, I am still encountering the same problem. I had some extra stuff in my other other project, so I created a new project following Google's directions to the letter. It worked as expected, so I cleared the code out of the loadView method and followed your directions exactly. I placed the second block of code in a method called drawMap that gets called by the viewDidLoad method using performSelector: withObject: afterDelay: after a delay of 5. This showed that the warning appears BEFORE the map is drawn. drawMap is still called, but no map is drawn. – user2105505 Feb 25 '13 at 17:12
  • 2
    I figured it out! Your solution worked perfectly, I just forgot to remove the empty loadView method. Since it had nothing in it, it was causing this error. Thanks! – user2105505 Feb 26 '13 at 13:33
3

I solved my problem just removing the loadview code that i took from the example. Just adding a view as sberley said should works.

just on thing more, on the identity inspector, that attribute that you have to change is class, at least it is on xcode 4.5

Ponja
  • 663
  • 1
  • 8
  • 15