简体   繁体   English

如何将谷歌地图添加到iOS6 SDK

[英]How to add google map to ios6 sdk

When i try to add Google map to ios6 according to this Link Google MAP 当我尝试添加谷歌地图根据这个链接iOS6的谷歌地图

and i get the API KEY and put it in my app but it crashed and the reason "Google MAP SDK for ios must be Initialized via [GMSServices ProvideAPIKey:...]" 并且我获取了API KEY并将其放入我的应用程序中,但是崩溃了,原因是“必须通过[GMSServices ProvideAPIKey:...]初始化ios的Google MAP SDK”

Can any body help me, give me video how to do it any thing ... 任何人都可以帮助我,给我视频如何做任何事情...

    #import "AppDelegate.h"
#import <GoogleMaps/GoogleMaps.h>
#import "ViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
[GMSServices provideAPIKey:@"AIzaSyBoOGGGQnvDydbKcxGeB1of6wu2ibE6Rjk"];

}

Did you do step 8 here ? 在这里做了步骤8吗?

If you did, can you update your question with the code for your application:didFinishLaunchingWithOptions: method? 如果您这样做了,是否可以使用您的application:didFinishLaunchingWithOptions:方法的代码来更新您的问题?

UPDATE: 更新:

Move the call to [GMSServices provideAPIKey:] higher up in the application:didFinishLaunchingWithOptions: method, somewhere before this line: 在以下行之前的位置,将调用移至application:didFinishLaunchingWithOptions:方法中更高的[GMSServices provideAPIKey:]

self.window.rootViewController = self.viewController;

This line sets the root view controller, which will cause the view controller's root view to be allocated, by calling loadView . 此行设置了根视图控制器,这将通过调用loadView导致分配视图控制器的根视图。 In Google's sample code loadView is what creates the GMSMapView , and so with the code as you have it now, you are trying to create a GMSMapView before providing the API key, which causes the Google Maps SDK for iOS to crash. 在Google的示例代码中, loadView是创建GMSMapView ,因此,如果您现在拥有的代码如此,则在提供API密钥之前尝试创建GMSMapView ,这会导致iOS的Google Maps SDK崩溃。

Also by the way, you had placed your call to [GMSServices provideAPIKey:] after the return statement, so it would never get called. 顺便说一句,您已将对[GMSServices provideAPIKey:]调用放置在return语句之后,因此它将永远不会被调用。

将您的GMSServices ProvideAPIKey移到didFinishLaunchingWithOptions的顶部,这将解决您的问题,因为您现在返回时要提供API密钥。

If you moved it and still get an error, here is what I did : 如果您将其移动但仍然出现错误,这是我所做的:

Copy the file GoogleMaps.bundle file into your framework folder in Xcode 将文件GoogleMaps.bundle复制到Xcode的框架文件夹中

"GoogleMaps.framework/Versions/A/Resources/GoogleMaps.bundle" “ GoogleMaps.framework / Versions / A / Resources / GoogleMaps.bundle”

..and make sure it's in your Targets (not Project) Build Phases settings under "Copy Bundle Resources" ..并确保它在“复制捆绑资源”下的“目标(不是项目)构建阶段”设置中

Start your delegate like this instead of yours : 这样启动您的代表,而不是您的代表:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [GMSServices provideAPIKey:@"AIzaSyB2LJ2ppIVtkNh0lkG9J1tXW2RcHtI0FKY"];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //////

}

I moved this line : 我移动了这一行:

[GMSServices provideAPIKey:@"myAPIKey"];

in the method viewDidLoad and now it works. 在方法viewDidLoad中 ,现在可以使用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM