繁体   English   中英

GoogleMaps基本的iOS演示应用程序崩溃 - 无法识别的选择器发送到实例

[英]GoogleMaps basic iOS demo app crash - unrecognized selector sent to instance

我试图运行基本的iOS演示SDK代码。 我已经创建了API密钥并且加载正常。 虽然我已经将viewDidLoad中的代码转移到了loadView,但效果仍然存在。 请参阅以下代码

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

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

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

使用描述抛出NSException - > - [GMSMapView animateToCameraPosition:]:发送到实例的无法识别的选择器。

*终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因是: ' - [GMSMapView中animateToCameraPosition:]:无法识别的选择发送到实例0x14dbb870' *第一掷调用堆栈:(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:与类型NSException的未捕获的异常终止

我想你可能忘了让这个类成为GMSMapView委托。 ()之后的GMSMapViewDelegate位需要在<>之间

我没有指定该委托以及谷歌基本代码不分配它。 我很幸运地设法让它发挥作用。 Google地图上的Google文档说明了以下内容:

选择项目而不是特定目标,然后打开“构建设置”选项卡。 在Other Linker Flags部分中,添加-ObjC。 如果看不到这些设置,请将“构建设置”栏中的过滤器从“基本”更改为“全部”。

但是他的示例项目,经过我的检查,已经设定了目标标志。 在我的案例中,在我的项目中的构建目标上设置它有帮助,我发布的代码工作正常。

在你的项目GoTo中添加-ObjC:点击你的Project-> Targets-> Build Setting->搜索(Other Linker Flags) - > Set(-ObjC)参考屏幕截图: 链接器标志

你很可能忘记这样做了:(如谷歌文档中所述)

选择项目而不是特定目标,然后打开“构建设置”选项卡。 在Other Linker Flags部分中,添加-ObjC。 如果看不到这些设置,请将“构建设置”栏中的过滤器从“基本”更改为“全部”。

我有同样的错误,因为我错误地写了-objC而不是-ObjC(用大写字母O)

如果它可以帮助某人

重要的是要注意,您应该将-ObjC添加到项目中的Other Linker Flags部分....不在您的特定目标中。

其他人已经从Google的文档中提到了以下部分

选择项目而不是特定目标,然后打开“构建设置”选项卡。 在Other Linker Flags部分中,添加-ObjC。 如果看不到这些设置,请将“构建设置”栏中的过滤器从“基本”更改为“全部”。

但是,直到我将-ObjC标志添加到我的项目'Other Linker Flags'部分,而不是目标'Other Linker Flags'部分,我能够解决无法识别的选择器错误。

我想你可能忘了让这个类成为GMSMapView委托。 ()之后的GMSMapViewDelegate位需要在<>之间

@interface StructuredGeocoderViewController () GMSMapViewDelegate

@end

@implementation StructuredGeocoderViewController {
  GMSMapView *_mapView;
  GMSGeocoder *_geocoder;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                          longitude:151.2086
                                                               zoom:12];

  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  _mapView.delegate = self;

  _geocoder = [[GMSGeocoder alloc] init];

  self.view = _mapView;
}

当你想将它提交到商店或测试航班时,也会将标志-ObjC放入发行版中 在此输入图像描述

您只需进行少量修改即可。

  1. 将Custom UIView的类名称指定为“GMSMapView”。
  2. 然后为你的班级打个出路。

    @IBOutlet var locationMapView:GMSMapView!

  3. 在ViewDidLoad()中添加以下代码。

    让camera = GMSCameraPosition.camera(withLatitude:10.1518,经度:76.3930,zoom:6.0)

     self.locationMapView.camera = camera let initialLocation = CLLocationCoordinate2DMake(10.1518, 76.3930) let marker = GMSMarker(position: initialLocation) marker.title = "Kochi" marker.snippet = "Kerala" marker.map = locationMapView marker.snippet = "Kerala" 

暂无
暂无

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

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