MKOverlay sometimes disappears

Go To StackoverFlow.com

8

I have two overlay options in my map: a MKCircleOverlay and a MKPolygonOverlay.The first is with variable radius, controlled via an UISlider.The last is customizable depending the number and position of the corners.If I change very fast the radius of the circle (reduce the value of UISlider) sometimes my overlay disappears (the circle) and after that the polygon cannot be drawn anymore (of course the circle too).No crashing of the app.What might it be?

Here is some code I use:

- (IBAction) addCircle:(id)sender
{
slider.hidden = NO;
slider.transform = CGAffineTransformMakeRotation(M_PI*(-0.5));

_longPressRecognizer= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
_longPressRecognizer.minimumPressDuration = 1.0; 

[mapview addGestureRecognizer:_longPressRecognizer];
[_longPressRecognizer release];
}

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
    return;
CGPoint touchPoint = [gestureRecognizer locationInView:mapview];    
CLLocationCoordinate2D touchMapCoordinate = [mapview convertPoint:touchPoint toCoordinateFromView:mapview];

MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = touchMapCoordinate;
pa.title = @"Circle Based Search";

[mapview addAnnotation:pa];
[pa release];

tmC = touchMapCoordinate;
double radius = 1000.0;

self.circleOverlay = [MKCircle circleWithCenterCoordinate:tmC radius:radius];
[mapview removeOverlays:[mapview overlays]];
[mapview addOverlay:circleOverlay];
[mapview removeAnnotations:[mapview annotations]];
}


-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay 
{
if ([overlay isKindOfClass:[MKCircle class]])
{
    MKCircleView* circleView = [[MKCircleView alloc] initWithOverlay:overlay] ;
    circleView.fillColor = [UIColor blueColor];
    circleView.strokeColor = [UIColor blueColor];
    circleView.lineWidth = 5.0;
    circleView.alpha = 0.20;
        return circleView;
}
else
    if ([overlay isKindOfClass:[MKPolygon class]])
{
    MKPolygonView *polygonView = [[MKPolygonView alloc] initWithOverlay:overlay ];
    polygonView.fillColor = [UIColor blueColor];
    polygonView.strokeColor = [UIColor blueColor];
    polygonView.lineWidth = 5.0;
    polygonView.alpha = 0.20;
    return polygonView;
}
return [kml viewForOverlay:overlay];
}

- (void)addCircleWithRadius:(double)radius
{
self.circleOverlay = [MKCircle circleWithCenterCoordinate:tmC radius:radius];
[mapview removeOverlays:[mapview overlays]];
[mapview addOverlay:circleOverlay];
[mapview removeAnnotations:[mapview annotations]];
}

- (IBAction)sliderChanged:(UISlider *)sender
{
    double radius = (sender.value);
[self addCircleWithRadius:radius];
[mapview removeAnnotations:[mapview annotations]];
}
2012-04-05 22:35
by Hari
Please show us the code you are using to resize the circle. Until we see that we can only guess as to what might be happening - sosborn 2012-04-06 05:15
Just done, sorry for that, I forgot totally to add code - Hari 2012-04-06 13:08
You should NSLog the radius in your sliderChanged to see if it is returning what you expect. Also log the tmc value to make sure the center is staying where you expect it to stay. Not sure of the code structure, but you might be activating the long touch recognizer when you move the slider slowly - sosborn 2012-04-06 13:43
Actually I see that its functioning, despite the absence of NSlogs, the size of the circle is changing as it would, and the center is visibly there,it doesn't change - Hari 2012-04-06 13:59
But is the radius what you expect it to be - sosborn 2012-04-06 23:09
Hmmm, visually it seems to be.Maybe you are right, I should put some NSLogs just to be sure, but as I said, visually it seems all OK, and it works fine, but sometimes when I scroll fast, reducing the radius, at some point the overlay disappears and cannot be shown anymore (same for polygons after this) - Hari 2012-04-06 23:43
[mapview addOverlay:circleOverlay]; should be [mapview addOverlay:self.circleOverlay] - med200 2012-04-10 20:50
Putted NSLogs, everything OK, changed `circleOverlay to self.circleOverlay but nothing.Moreover, when chenged to self.circleOverlay the app crashed - Hari 2012-04-11 09:59


3

Problem solved.It was something with UISlider, in the nib, in the inspector of the slider under Values the property Continuous was checked.After I unchecked that, the problem was resolved.

2012-04-11 13:28
by Hari
Ads