Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 997
user2105505 Avatar asked Feb 25 '13 02:02

user2105505


People also ask

Is Google Maps API free for commercial use?

All Maps Embed API requests are available at no charge with unlimited usage.

What can you do with Google Maps API?

Google Maps APIs are prepackaged pieces of code that let you quickly and easily include maps on your websites or in your mobile apps – and then add extra functions to your applications. They're available for Android, iOS and web browsers, and as HTTP web services that let you pass information between systems.

What is Street View in Google Maps?

Street View, by Google Maps, is a virtual representation of our surroundings on Google Maps, consisting of millions of panoramic images. Street View's content comes from two sources - Google and contributors. Through our collective efforts, we enable people everywhere to virtually explore the world.


2 Answers

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];
like image 109
sberley Avatar answered Oct 19 '22 11:10

sberley


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

like image 23
Ponja Avatar answered Oct 19 '22 11:10

Ponja