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

I am trying to use the Google Maps SDK for iOS in the view of the main view that I created in the storyboard, and is connected to the view controller via IBOutlet (I called it extraView, subclassed from UIView). When I follow the instructions in the SDK getting started guide, the SDK works fine, but it uses the topmost view in the hierarchy (main view), which I don't want. I want my map to be in the smaller part of the screen and use the rest of the screen for something else. When I try 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 message on the console output:

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

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

+5
source share
2 answers

Here's how ...

  • add a UIView to the view controller where you work.
  • set the class value GMSMapViewin the identity inspector.

Then drag it into your code, as with any other outlet.

You can lazily create an instance in your setter ...

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

To display the map, a sample Google code will be ...

  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
                                                          longitude:103.848
                                                               zoom:12];
  self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
+13
source

I solved the problem by simply removing the loadview code that I took from the example. Just adding a view, as Sberley said, should work.

, , , , , , xcode 4.5

+3

All Articles