ios - 如何解决在 Xcode 中使用 Google Maps SDK for iOS 时出现的错误 "Thread 1: SIGABRT error"

标签 ios xcode google-maps google-maps-sdk-ios

我按照Google Maps SDK for iOS - Getting started 链接中提到的步骤进行操作。 以下是我创建的文件

AppDelegate.m

#import "AppDelegate.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];
    [GMSServices provideAPIKey:@"AIzaXXXXXXXXXXeGuCyxChdTECXXXXXXXXXXV9E"];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    return YES;
}
//Other functions are there as it is.

ViewController.m

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

@interface ViewController ()

@end

@implementation ViewController 
{
    GMSMapView *mapView_;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadView 
{
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                        longitude:151.20
                                                             zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    self.view = mapView_;

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;
}

@end

ma​​in.m

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool 
    {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        //Error is displayed in the above line.
    }
}

以下是错误的详细信息

2013-04-23 17:02:37.482 GMap[8146:12e03] +[GMSCameraPosition cameraWithLatitude:longitude:zoom:]: unrecognized selector sent to class 0x25ad5c
2013-04-23 17:02:37.483 GMap[8146:12e03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[GMSCameraPosition cameraWithLatitude:longitude:zoom:]: unrecognized selector sent to class 0x25ad5c'
*** First throw call stack:
(0x2418012 0x223de7e 0x24a32ad 0x2407bbc 0x240794e 0x2bb4 0x1262ff8 0x1263232 0x11b23d5 0x11b276f 0x11b2905 0x11bb917 0x27ad 0x117f157 0x117f747 0x118094b 0x1191cb5 0x1192beb 0x1184698 0x3133df9 0x3133ad0 0x238dbf5 0x238d962 0x23bebb6 0x23bdf44 0x23bde1b 0x118017a 0x1181ffc 0x24bd 0x23e5)
libc++abi.dylib: terminate called throwing an exception

最佳答案

您的错误是:

'+[GMSCameraPosition cameraWithLatitude:longitude:zoom:]: unrecognized selector sent to class 0x25ad5c'

根据似乎定义的SDK。这是如何定义的?如果它是一个类别,您可能需要使用标志 -ObjC 和 -all_load 链接到 SDK。

关于ios - 如何解决在 Xcode 中使用 Google Maps SDK for iOS 时出现的错误 "Thread 1: SIGABRT error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16168818/

相关文章:

ios - 在 iOS 应用程序中添加应用程序事件会产生未声明的标识符 'AppEvent'

javascript - 通过右键单击事件从 Google Maps API 3 获取坐标

ios - 以编程方式定位按钮,结果出乎意料

ios - 更改 UICollectionViewCell 中的标签位置

ios - 我多次尝试都收到错误。存档验证因错误而失败

ios - JSQMessagesViewController 更改发送按钮 TextView 占位符的语言

C++ - Xcode 程序

javascript - map 在检查元素或缩放后工作

android - 有谁知道一个简单的 "You are here"Android map 教程?

android - 如何从 href =""在移动设备上打开 facebook native 应用程序