我创建了 API 密钥并在谷歌提供的演示项目中进行了尝试,谷歌地图工作正常。但是,尝试创建示例项目并集成 google map sdk 在运行时崩溃。
遵循的步骤
创建了一个禁用 USE STORYBOARDS 和 ARC 的单视图应用程序。使用我的项目的包标识符创建了一个 API 密钥,它是 rosnMapTest 将 GoogleMapsframework 包复制到框架组中。将 GoogleMapsbundle 从 Resources 文件夹复制到 Framework 组添加了以下所有框架
<pre>
<code>
AVFoundation.framework
CoreData.framework
CoreLocation.framework
CoreText.framework
GLKit.framework
ImageIO.framework
libicucore.dylib
libstdc++.dylib
libz.dylib
OpenGLES.framework
QuartzCore.framework
SystemConfiguration.framework
</code>
</pre>
Fixed the default Architectures and Other Linker Flags
Imported GoogleMaps.h and added google API key in AppDelegate
<pre>
<code>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[GMSServices provideAPIKey:@"AIzaSyAVEDscm0b307ZDFpOnn4zr4saLJF43E0Y"];
return YES;
}
</code>
</pre>
Added following code in viewcontroller
<pre>
<code>
#import "TestViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface TestViewController ()
@end
@implementation TestViewController
GMSMapView *mapView_;
- (void) viewDidLoad
{
[super viewDidLoad];
}
- (void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
options.title = @"Sydney";
options.snippet = @"Australia";
[mapView_ addMarkerWithOptions:options];
}
@end
</code>
</pre>
<pre>
<code>
Error in RUNTIME: “2013-02-23 19:37:27.697 MapTest[2947:c07] +[GMSCameraPosition cameraWithLatitude:longitude:zoom:]: unrecognized selector sent to class 0xf2a4
(lldb)”
</code>
</pre>