GoogleMaps 基本 iOS 演示应用程序崩溃 - 无法识别的选择器发送到实例 [英] GoogleMaps basic iOS demo app crash - unrecognized selector sent to instance

查看:27
本文介绍了GoogleMaps 基本 iOS 演示应用程序崩溃 - 无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行基本的 iOS 演示 SDK 代码.我已经创建了 API 密钥并且可以正常加载.虽然我已经将代码从 viewDidLoad 转移到 loadView 效果仍然存在.看下面的代码

Im trying to run the basic iOS demo SDK code. I have created the API keyand it loads ok. Although i've transfered the code from viewDidLoad to loadView the effect remains. See the following code

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

相机已创建,但当此行执行时

The camera is created but when this line is executed

_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

NSException 被抛出并带有描述 -> -[GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance.

an NSException is thrown with the description -> -[GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance.

* 由于未捕获的异常NSInvalidArgumentException"而终止应用程序,原因:-[GMSMapView"animateToCameraPosition:]: 无法识别的选择器发送到实例0x14dbb870'* 第一次抛出调用栈:(0x2f462f4b 0x39cd96af 0x2f4668e7 0x2f4651cb 0x2f3b44d8 0x4cebe9 0x4cd78f 0x4ccc41 0x4ccb3d5 0x20x31bda1bd 0x31bda139 0x1d4b27 0x1d4a83 0x1d51cd 0x31bda37b 0x31c850f10x31c85007 0x31c845e3 0x31c8430d 0x31c8407d 0x31c84015 0x31bd5da30x3185cc6b 0x3185847b 0x3185830d 0x31857d1f 0x31857b2f 0x31bce0c30x2f42e1cd 0x2f42bb71 0x2f42beb3 0x2f396c27 0x2f396a0b 0x340972830x31c3a049 0xf58b1 0x3a1e1ab7) libc++abi.dylib:终止于NSException 类型的未捕获异常

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GMSMapView animateToCameraPosition:]: unrecognized selector sent to instance 0x14dbb870' * First throw call stack: (0x2f462f4b 0x39cd96af 0x2f4668e7 0x2f4651cb 0x2f3b44d8 0x4cebe9 0x4cd78f 0x4ccc41 0x4ccb3d 0x21ced5 0x31bda1bd 0x31bda139 0x1d4b27 0x1d4a83 0x1d51cd 0x31bda37b 0x31c850f1 0x31c85007 0x31c845e3 0x31c8430d 0x31c8407d 0x31c84015 0x31bd5da3 0x3185cc6b 0x3185847b 0x3185830d 0x31857d1f 0x31857b2f 0x31bce0c3 0x2f42e1cd 0x2f42bb71 0x2f42beb3 0x2f396c27 0x2f396a0b 0x34097283 0x31c3a049 0xf58b1 0x3a1e1ab7) libc++abi.dylib: terminating with uncaught exception of type NSException

推荐答案

我想您可能忘记将类设为 GMSMapView 委托.() 之后的 GMSMapViewDelegate 位需要介于 <>

I think you may have forgotten to make the class a GMSMapView delegate. The GMSMapViewDelegate bit after the () needs to be between <>

我没有分配该委托,Google 的基本代码也没有分配它.我幸运地设法让它工作.谷歌地图上的谷歌文档说明如下:

I don't assign that delegate as well as Googles Base Code does not assign it. I have fortunetly managed to get it working. The google documentation on Google Maps states what follows:

选择您的项目,而不是特定的目标,然后打开构建设置"选项卡.在其他链接器标志部分,添加 -ObjC.如果这些设置不可见,请将构建设置"栏中的过滤器从基本"更改为全部".

Choose your project, rather than a specific target, and open the Build Settings tab. In the Other Linker Flags section, add -ObjC. If these settings are not visible, change the filter in the Build Settings bar from Basic to All.

但是,经过我的检查,他们的示例项目已将标志设置为目标.在我的案例中,将它设置在我的项目中的构建目标上有所帮助,并且我发布的代码工作正常.

But their example project, after my examination, has the flag set on target. Setting it on the build target within my project in my case helped and my posted code works fine.

这篇关于GoogleMaps 基本 iOS 演示应用程序崩溃 - 无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆