我有加载地图视图并在其上放置标记的代码。我基本上已将我的代码重构为用于添加 GMSMarker 的 Google 示例代码。该应用程序在模拟器 (8.4) 中运行没有问题,但是当标记代码添加到我的 iPhone 6 ( marker.map = mapView_
) 上的地图时,应用程序崩溃并且我在 Xcode 中收到错误:EXC_BAD_ACCESS (code=1, address=0x0) .
当我删除marker.map = mapView_
代码行时,mapView 可以在手机上正常加载。下面是我在 viewDidLoad: 中简化代码的内容。
GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:loc zoom:12.5];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.settings.myLocationButton = YES;
mapView_.settings.tiltGestures = NO;
mapView_.settings.rotateGestures = NO;
mapView_.delegate = self;
dispatch_async(dispatch_get_main_queue(), ^{
mapView_.myLocationEnabled = YES;
});
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = camera.target;
marker.snippet = @"Hello World";
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = mapView_;