我在 map 上选择标记时发生随机崩溃。您在代码中看到的标记是自定义的,当点击它们时,标记的图标将被隐藏,并放置自定义信息 View 。 所有委托(delegate)方法每次都会正常执行,因此崩溃并不直接在我的代码中,但我可能会做一些“扰乱”谷歌地图的事情
0 libsystem_kernel.dylib 0x000000019a8f9cc8 __kill + 8
1 libsystem_platform.dylib 0x000000019a977b18 _sigtramp + 68
2 QuartzCore 0x0000000190908038 -[CALayer _renderBorderInContext:] + 112
3 QuartzCore 0x0000000190906b64 -[CALayer renderInContext:] + 1032
4 SP 0x000000010036abf4 -[GMSMapView setSelectedMarker:] + 196
5 SP 0x000000010036befc -[GMSMapView didTapMarker:] + 112
6 SP 0x0000000100381830 -[GMSMarker wasTapped] + 60
7 SP 0x000000010028fa14 -[GMSVectorMapView didTapAt:] + 1252
8 UIKit 0x0000000190e6ec48 _UIGestureRecognizerSendActions + 212
9 UIKit 0x0000000190cfd284 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 376
10 UIKit 0x00000001910fc03c ___UIGestureRecognizerUpdate_block_invoke + 56
11 UIKit 0x0000000190cbe240 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 284
12 UIKit 0x0000000190cbcb1c _UIGestureRecognizerUpdate + 208
13 CoreFoundation 0x000000018dcc3854 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
14 CoreFoundation 0x000000018dcc0adc __CFRunLoopDoObservers + 368
15 CoreFoundation 0x000000018dcc0e68 __CFRunLoopRun + 760
16 CoreFoundation 0x000000018dc01dcc CFRunLoopRunSpecific + 448
17 GraphicsServices 0x00000001938e9c08 GSEventRunModal + 164
18 UIKit 0x0000000190d32fc0 UIApplicationMain + 1152
19 SP 0x00000001000590e0 main (main.m:14)
20 libdyld.dylib 0x000000019a7ffa9c start + 0
异常类型:EXC_BAD_ACCESS (SIGSEGV) 现在这是 map 的代码。 我正在使用带有自动布局的 Storyboard
- (void)viewDidLoad
{
[super viewDidLoad];
#ifdef DEBUG
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.780528
longitude:-73.961009
zoom:kZoomMin];
#else
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[LocationManager sharedInstance].currentLocation.coordinate.latitude
longitude:[LocationManager sharedInstance].currentLocation.coordinate.longitude
zoom:12];
#endif
CGFloat width = [UIScreen mainScreen].bounds.size.width;
CGFloat height = [UIScreen mainScreen].bounds.size.height;
//Setting map
self.mapView = [GMSMapView mapWithFrame:CGRectMake(0, 0, width, height) camera:camera];
self.mapView.settings.compassButton = NO;
self.mapView.settings.myLocationButton = NO;
self.mapView.accessibilityElementsHidden = NO;
self.mapView.myLocationEnabled = YES;
self.mapView.buildingsEnabled = NO;
self.mapView.indoorEnabled = NO;
self.mapView.delegate = self;
…
}
markerInfoWindow 委托(delegate)方法的描述说我应该避免更改超过 500x500 px 的 map 大小并避免更改标记,我已经删除了所有标记的调用,但它还是崩溃了 我尝试检查我是否在主线程上使用了mapView,我用[NSThread currentThread]检查了它,它似乎总是在主线程中,请让我知道是否有更好的方法来检查它
#pragma mark - GMSMapViewDelegate
- (UIView *)mapView:(GMSMapView *)mapView
markerInfoWindow:(GMSMarker *)marker
{
UIView *infoWindow = [[UIView alloc] init];
infoWindow.frame = CGRectMake(0, 0, 240, 54);
infoWindow.backgroundColor = [UIColor clearColor];
infoWindow.layer.cornerRadius = 10;
infoWindow.layer.masksToBounds = YES;
infoWindow.layer.borderColor = (__bridge CGColorRef)([UIColor blackColor]);
infoWindow.layer.borderWidth = 5;
ParkingLot *parkingLot = (ParkingLot *)marker.userData;
if (![parkingLot isKindOfClass:[ParkingLot class]])
{
return nil;
}
NSString *backgroundImageName = nil;
switch ([parkingLot.parentCompanyId intValue])
{
case 1:
backgroundImageName = @"00_logo_pin_globo_b.png";
break;
case 2:
backgroundImageName = @"00_logo_pin_globo_c.png";
break;
case 3:
backgroundImageName = @"00_logo_pin_globo_a.png";
break;
}
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:backgroundImageName]];
CGRect frame = background.frame;
frame.origin.y++;
frame.origin.x++;
[background setFrame:frame];
[infoWindow addSubview:background];
UILabel *locationName = [[UILabel alloc] init];
locationName.font = [UIFont fontWithName:@"Helvetica" size:12];
locationName.frame = CGRectMake(45, 10, 110, 13);
locationName.textColor = [UIColor redColor];
[infoWindow addSubview:locationName];
if ([marker.userData isKindOfClass:[SearchResult class]])
{
Address *address = (Address *)marker.userData;
ASSERT_CLASS(address, Address);
UILabel *addressLabel = [[UILabel alloc] init];
addressLabel.frame = CGRectMake(5, 5, 60, 20);
addressLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
[addressLabel setTextColor:[UIColor whiteColor]];
[infoWindow addSubview:addressLabel];
addressLabel.text = address.name;
[infoWindow setFrame:CGRectMake(0, 0, 100, 30)];
infoWindow.backgroundColor = [UIColor blackColor];
[background removeFromSuperview];
}
else
{
UILabel *addressLabel = [[UILabel alloc] init];
addressLabel.frame = CGRectMake(45, 22, 90, 20);
addressLabel.font = [UIFont fontWithName:@"Helvetica" size:8];
addressLabel.text = parkingLot.lotAddress;
addressLabel.lineBreakMode = NSLineBreakByWordWrapping;
[addressLabel setNumberOfLines:2];
[infoWindow addSubview:addressLabel];
if ([parkingLot.hasCoupon intValue] == 1)
{
UIImageView *hasCouponImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"00_logo_icon_%_.png"]];
[hasCouponImageView setCenter:CGPointMake(background.frame.size.width - (hasCouponImageView.frame.size.width * 2.4), background.frame.size.height * 0.45)];
[infoWindow addSubview:hasCouponImageView];
}
locationName.text = parkingLot.locationName;
}
return infoWindow;
}
- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker
{
ParkingLot *parkingLot = [marker userData];
[self.delegate pushToParkingLot:parkingLot];
}
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
if ([self.mapView isEqual:self.informationWindowsMarker.map])
{
if(marker.position.latitude != self.informationWindowsMarker.position.latitude &&
marker.position.longitude != self.informationWindowsMarker.position.longitude)
{
[self.informationWindowsMarker setOpacity:1];
TRACE(@"%@", [self.informationWindowsMarker debugDescription]);
}
}
self.informationWindowsMarker = nil;
self.informationWindowsMarker = marker;
[marker setOpacity:0];
return NO;
}
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
if ([self.mapView isEqual:self.informationWindowsMarker.map])
{
ParkingLot *parkingLot = (ParkingLot *)self.informationWindowsMarker.userData;
if (![self.informationWindowsMarker.icon isEqual:[parkingLot logoMarkerImage]])
{
self.informationWindowsMarker.icon = [parkingLot logoMarkerImage];
}
[self.informationWindowsMarker setOpacity:1];
}
}
最佳答案
删除
infoWindow.layer.cornerRadius = 10;
infoWindow.layer.masksToBounds = YES;
infoWindow.layer.borderColor = (__bridge CGColorRef)([UIColor blackColor]);
infoWindow.layer.borderWidth = 5;
解决了崩溃问题
我不太清楚为什么,但是修改图层的属性使用了 CoreAnimation,并且可能会使用他自己的线程来更改它,从而为 Google 的 API 生成不稳定的状态
关于ios - 选择标记时 Google-Maps-iOS-SDK 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29150939/