Change MKOverlay coordinate for MKOverlayView

I have an overlay on the map, and I would like to change its coordinates. To make this easy, I'm going to call the setNeedsDisplayInMapRect: method after making changes to the view.

I tested this by simply changing fillColor and it works fine:

overlayView.fillColor = [[UIColor greenColor] colorWithAlphaComponent:0.3]; [overlayView setNeedsDisplayInMapRect:mapView.visibleMapRect]; 

However, I seem to have hit a brick wall, trying to also change the coordinates of the center of my overlay ( MKCircleView with MKCircle ). There is a method in MKAnnotation that corresponds to MKCircle called setCoordinate: - which seems to me necessary. However, unfortunately, the circle property in MKCircleView is read-only. In addition, the overlay property in MKOverlayView is also read-only.

Is there a way to change the coordinates for the overlay without resorting to removing the overlay and adding a new one (which will cause a very noticeable flicker on the screen.)?

+6
source share
1 answer

the same problem arises here, so I create a set of methods and call them as required.

 -(void)removeAllAnnotationFromMapView{ if ([[self.tmpMapView annotations] count]) { [self.tmpMapView removeAnnotations:[self.tmpMapView annotations]]; } } -(void)removeAllOverlays{ if ([[self.tmpMapView overlays] count]) { [self.tmpMapView removeOverlays:[self.tmpMapView overlays]]; } } -(void)removeOverlayWithTag:(int)tagValue{ for (MKOverlayView *oView in [self.tmpMapView overlays]) { if (oView.tag == tagValue) { [self.tmpMapView removeOverlay:oView]; } } } 
0
source

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


All Articles