MKCircle does not update the radius, but it translates

I have to draw MKCicle in MKMapView. Then I have to re-draw it when the user through the slider changes the radius. I delete it and I recreate it by re-adding it to the map. But instead of doing what I expect, I see that MKCircle translates on the map, maintaining the same size.

Here is my code:

- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id)overlay { MKOverlayView* overlayView = nil; if(overlay == self.circle) { //if we have not yet created an overlay view for this overlay, create it now. if(nil == self.circleView) { self.circleView = [[[MKCircleView alloc] initWithCircle:self.circle] autorelease]; self.circleView.fillColor = [UIColor blueColor]; self.circleView.strokeColor = [UIColor blueColor]; self.circleView.alpha = 50; self.circleView.lineWidth = 2; } overlayView = self.circleView; } return overlayView; } -(void)drawPolygonWithLocation { [self.mapView removeOverlay: self.circle]; MKCoordinateRegion region; region.center.latitude = self.geofenceLocation.latitude; region.center.longitude = self.geofenceLocation.longitude; region.span.latitudeDelta = 0.005; region.span.longitudeDelta = 0.005; MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits: region]; [self.mapView setRegion:adjustedRegion animated:TRUE]; self.radius = (double)(slRadius.value); NSLog(@"Raggio: %f", self.radius); NSLog(@"Lat: %f, Lon: %f", region.center.latitude, region.center.longitude); self.circle = [MKCircle circleWithCenterCoordinate:self.geofenceLocation.coordinate radius: self.radius]; NSLog(@"CIRCLE: radius %f Lat: %f, Lon: %f", self.circle.radius, self.circle.coordinate.latitude, self.circle.coordinate.longitude); [self.mapView addOverlay:self.circle]; } -(IBAction)updateRadius:(id)sender { [self drawPolygonWithLocation]; } 

NSLog writes to the right values โ€‹โ€‹of the console, the center does not change, and the radius changes according to user input. But, again, MKCircle is moving northwest.

Thanks in advance Samuel Rabini

+4
source share
1 answer

Fixed. I just add

 self.circleView = nil; 

front

 [self.mapView addOverlay:self.circle]; 

so it works great.

Samuel

+3
source

Source: https://habr.com/ru/post/1389747/


All Articles