在我的应用程序中,我想向地图添加叠加层,当用户拖动滑块时,叠加层圆半径必须改变,但有时会抛出线程异常。我的代码:
- (void)addCircleWithRadius:(NSNumber *)radius
{
MKCircle *circle = [MKCircle circleWithCenterCoordinate:userlocation radius:[radius doubleValue] ];
[circle setTitle:@"background"];
MKCircle *circleLine = [MKCircle circleWithCenterCoordinate:userlocation radius:[radius doubleValue]];
[circleLine setTitle:@"line"];
NSArray *overlays = [NSArray arrayWithObjects:circle,circleLine, nil];
[mapView addOverlays:overlays];
}
-(void)slider_change:(id)sender
{
@try {
[mapView removeOverlays:[mapView overlays]];
if([mapView.overlays count] == 0)
{
CLLocationCoordinate2D _coordinate ;
_coordinate.latitude = 35.692995;
_coordinate.longitude = 51.421509;
NSNumber *value = [NSNumber numberWithFloat:slider.value * 1000];
[self addCircleWithRadius:value];
}
}
@catch (id exception) {
}
}