Using the Google Maps SDK in views other than the main view - google-maps-sdk-ios

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.

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];

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

Related

presentControllerWithName in tvOS

in watchOS I used presentControllerWithName to show a View Controller and to pass the context in this way
presentControllerWithName("NameOfTheViewController", context:"PassedContext")
Which is the equivalent in tvOS?
Best Regards
As noted in other answers, the way to programmatically show another view controller in tvOS (or iOS) is performSegueWithIdentifier:sender:. (Or presentViewController:animated:completion: if you're not getting your VCs from a storyboard flow.)
But you might not need to do it programmatically. In watchOS it's sometimes easiest to do it that way, but in iOS & tvOS, it's common to make controls directly perform storyboard transitions entirely from Interface Builder. Just control-drag (right-click-drag) from the button to another view controller. (More step-by-step instructions in Xcode Help.)
Unlike watchOS, the view controller transitions in iOS & tvOS don't include a way to pass context information. Not as part of the API, at least — you have to include a bit of glue code yourself to do that. How to do that is a pretty common question.
If you're using storyboard segues (generally, you should), the prepareForSegue:sender: method is typically where you do this — you get a reference to the new view controller that's about to be shown, and use some function or property you've defined on that view controller to pass it some context. It often looks something like this:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == mySegueIdentifier {
guard let destination = segue.destinationViewController as? MyViewControllerClass
else { abort("unexpected storyboard segue") }
destination.someProperty = someValue
}
}
You can find good examples of this when you create a new Xcode project with the Master-Detail App template.
tvOS is more similar to iOS than it is to watchOS, although they all have some similarities. In tvOS (like in iOS) you can use both performSegueWithIdentifier:sender: or presentViewController:animated:completion: depending on your situation.
For more on this, you can check out the UIViewController class reference.

transitionViewForCurrentTransition is not set error

Here is my project:
It only crashes in iOS8.
I have 5 view controllers:rootViewController,A,B,C and D.Every view controller has a button that present another view controller except D. Evert time presenting a view controller, the Manager singleton object will add the presented view controller into an array. The last view controller D, which has a dismiss button, will use the array to dismiss view controller,and here's the code:
while ([Manager sharedManager].viewCont.count) {
UIViewController *viewController = [[Manager sharedManager].viewCont lastObject];
[viewController dismissViewControllerAnimated:NO completion:nil];
[self removeViewCon];
}
But I meet a crash,which shows:
I use some manage object because I want to manage the view controllers in some case.
My question is why this crash occurs when in "while" statement? Is it about runloop or iOS8 has some features like UIPresentationController that will not allow this case? And how to fix this?
Thanks in advance.
I just hit this also. It seemes the UIPresentationController crashes if it's presenting view disappears before it is done using it. One fix is to keep the view controller around a little bit longer.

Google Maps IOS SDK 1.2 need snapshot of map view

In 1.1, the GMSScreenshot class provided a rudimentary way to get a snapshot of the entire screen into a UIImage. In 1.2, the class is missing, and in the release notes, it says this:
Calling renderInContext: on the GMSMapView layer now renders correctly;
this allows for snapshots and UI effects
Unfortunately, I'm not finding this to be the case. Typically renderInContext: does not work on Open GL drawing, but I figured I'd take a shot anyway (it didn't work). Has anyone been successful in getting a (preferred) view or screen snapshot?
I am able to take a screenshot. Here is the code I use:
UIGraphicsBeginImageContext(mapView_.frame.size);
[mapView_.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I do not call this straight after I create the map as it can take some frames for the map to render.

uiviewcontroller black

I've just created a storyboard with few table controllers and one view controller.
Everything works fine until my app push the view controller: it's shown completely black.
I can add map view, image view or whatever, or even nothing (a complete empty view controller), but it's always shown black.
I push it using the the navigation [self.navigationController pushViewController] code line.
This is not happening with table controllers, just with view controllers.
Any suggestion?
I'm using Xcode 4.3.2 4E2002.
Thanks in advance,
Samuel
Have you defined your storyboard correctly? This behavior could happen if you failed to properly initialize your storyboard and instantiate your controller from the storyboard. IE, you need to create a UIStoryboard object and need to instantiate your controller by calling
[storyboardObject instantiateViewControllerWithIdentifier: #"controllerName"]; ...See the thread here: http://mobile.tutsplus.com/tutorials/iphone/ios-5-sdk-storyboards

Only direct subviews of the MainWindow view gets orientation set by iOS?

Whenever my app is rotated, only the viewController of which I've added his view as a subview to the mainwindow gets his interfaceOrientation property updated, the rest remains ignorant of the fact the device has been rotated.
Is it my responsibilty to notify other objects of the change, and if so, what's a nice way to do it?
I've looked into setting interfaceOrientation of my children-viewcontrollers but that's readonly.
Thanks in advance,
I found that calling
willRotateToInterfaceOrientation
and/or
didRotateFromInterfaceOrientation
of the view controller you are going to show worked for me. In my case I was using a Navigation Controller so it was easy to keep track of what was going to be shown to the user next. Below is some code from my project.
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
[viewController willRotateToInterfaceOrientation:
[self interfaceOrientation] duration:0];
}