我在地图上选择标记时发生了随机崩溃。您可以在代码中看到的标记是习惯,当它们被点击时,标记的图标被隐藏并且放置了自定义信息视图。 每次都会正常执行所有委托方法,因此崩溃不是直接在我的代码中,但我可能正在做一些事情,并且#34;烦恼"谷歌地图
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) 现在这里是地图的代码。 我使用自动布局的故事板
- (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委托方法的描述说我应该避免将地图大小更改为500x500像素并避免更改标记,我已经删除了所有标记的调用,但无论如何它都会崩溃 我尝试检查我是否在主线程上使用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];
}
}
答案 0 :(得分:0)
删除
infoWindow.layer.cornerRadius = 10;
infoWindow.layer.masksToBounds = YES;
infoWindow.layer.borderColor = (__bridge CGColorRef)([UIColor blackColor]);
infoWindow.layer.borderWidth = 5;
解决了崩溃问题
我不太清楚为什么,但修改图层的属性会使用CoreAnimation,并且可能会使用自己的线程来更改它,然后为Google的API生成不稳定状态