13

这是一个单视图应用程序,我按照链接 https://developers.google.com/maps/documentation/ios/start 中的说明将谷歌地图 SDK 添加到 iOS6。错误是:

unrecognized selector sent to class 0xe2b0
2013-02-07 15:21:29.788 mapApp[2061:12e03] *** Terminating app due to uncaught exception     
'NSInvalidArgumentException', reason: '+[GMSCameraPosition    
cameraWithLatitude:longitude:zoom:]: unrecognized selector sent to class 0xe2b0'

AppDelegate.m

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

   //initializing google map api key
   [GMSServices provideAPIKey:@"google's api key goes here"];

   [self.window makeKeyAndVisible];
   return YES;

}

视图控制器.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.

   GMSCameraPosition *cam = [GMSCameraPosition cameraWithLatitude:13.0245231 
                                                        longitude:77.64072579999993                
                                                             zoom:6];

   mapView = [GMSMapView mapWithFrame:CGRectZero camera:cam];
   mapView.myLocationEnabled = YES;

   GMSMarkerOptions *options = [[GMSMarkerOptions alloc]init ];
   options.position = CLLocationCoordinate2DMake(13.025738,77.637809);
   options.title = @"ensign";
   options.snippet = @"kalyan nagar";

   [mapView addMarkerWithOptions:options];

}

主文件

#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv,nil, NSStringFromClass([AppDelegate class]));
    }
}

在跟踪错误时,它在执行第一行后来自方法的return语句中显示main.m-viewDidLoad

GMSCameraPosition *cam = [GMSCameraPosition cameraWithLatitude:13.0245231 
                                                    longitude:77.64072579999993                
                                                         zoom:6];

它逃脱了其余的行。

4

3 回答 3

25

您是否在说明-ObjC的第 7 步中添加了其他链接器标志?

-- 额外信息编辑:注意-ObjC区分大小写。

于 2013-02-08T00:07:08.063 回答
8

我有同样的问题。确保将 -ObjC 标志添加到“目标”而不是“项目”的“构建设置”中。

PS 在这两个地方添加它也不会破坏它。

于 2013-04-19T03:27:59.537 回答
0

谷歌文档说选择你的项目,而不是一个特定的目标,然后打开构建设置选项卡。在其他链接器标志部分中,添加 -ObjC。如果这些设置不可见,请将 Build Settings 栏中的过滤器从 Basic 更改为 All。有时这是错误的......我还必须将链接器标志添加到目标中,以使其正常工作。这应该可以帮助某人

于 2014-01-30T12:05:57.530 回答