Change coordinate of MKOverlay for an MKOverlayView

心已入冬 提交于 2019-12-21 04:35:07

问题


I have an overlay on the map, and I would like to change its coordinates. To do this seamlessly I'm going to call the setNeedsDisplayInMapRect: method after the change has been made to the view.

I've tested this out by just changing the fillColor and it works fine:

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

However I've seemingly hit a brick wall trying to also change the center coordinates of my overlay view (which is an MKCircleView with an MKCircle). There is a method in MKAnnotation, which MKCircle conforms to, called setCoordinate: - which seems like what I need. Unfortunately though, the circle property in MKCircleView is readonly. Moreover the overlay property in MKOverlayView is also readonly.

Is there actually a way of changing the coordinates for an overlay, without resort to remove the overlay view and adding a new one (which would cause very noticeable flicker on the screen.) ?


回答1:


same problem is occurred here , so i'm creating set of method and calling it according to requirement.

-(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];
        }
    }
}


来源:https://stackoverflow.com/questions/9058612/change-coordinate-of-mkoverlay-for-an-mkoverlayview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!