0

在我的应用程序中,我想向地图添加叠加层,当用户拖动滑块时,叠加层圆半径必须改变,但有时会抛出线程异常。我的代码:

- (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) {

    }

}
4

1 回答 1

0
-(IBAction)slider_action:(id)sender
{

    [map removeOverlays:[map overlays]];

    double radius1 = (slider.value * 5000);

    NSLog(@"%f",radius1);

    [self addCircleWithRadius:radius1 addCircleWithCoordinate:theCoordinate1];
}

-(void) addCircleWithRadius:(double)radius1 addCircleWithCoordinate: (CLLocationCoordinate2D) coordinate
{
    MKCircle *circle1 = [MKCircle circleWithCenterCoordinate:coordinate radius:radius1];

    [map addOverlay:circle1];
}
- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{

    MKCircle* circle1 = overlay;
    MKCircleView *circleView = [[MKCircleView alloc] initWithCircle:circle1];

    circleView.alpha = 0.25;
    circleView.lineWidth = 2.0;

    circleView.strokeColor = [UIColor blackColor];
    circleView.fillColor = [UIColor redColor];

    return circleView;
}
于 2013-01-01T10:55:30.193 回答