2012-01-30 81 views
6

我在地图上覆盖了一层,我想更改它的坐标。要做到这一点无缝地进行,我将在对视图进行更改之后调用setNeedsDisplayInMapRect:方法。为MKOverlayView更改MKOverlay的坐标

我已经只是改变了填充颜色测试了这一点,它工作正常:

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

不过我貌似撞了南墙努力也改变我的重叠视图的中心坐标(这是MKCircleViewMKCircle)。 MKCircle符合的 MKAnnotation中有一种方法,称为setCoordinate: - 这看起来像我所需要的。不幸的是,MKCircleView中的circle属性是只读的。此外,MKOverlayView中的overlay财产也是只读的。

实际上是否有改变覆盖层坐标的方法,而不求助于移除覆盖层视图并添加一个新层(这会在屏幕上引起非常明显的闪烁)?

+0

我有类似的问题查看MKPolyline。在我的情况下,这条线总是变长,所以我总是画两条折线,然后去掉那条较老的线。这样,较长的线隐藏了闪烁。 – theaob 2013-08-16 10:06:15

回答

0

同样的问题发生在这里,所以我创建了一套方法,并根据需要调用它。

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