如何在注释周围添加圆作为半径

时间:2011-11-11 03:59:54

标签: iphone objective-c xcode sdk

我有一个MKMapView。我需要在注释周围添加一个圆作为半径(比如距离位置1km)。

我原本认为这是某种形式的MKAnnotation,但我在文档中找不到任何解释这一点的内容。有谁知道这是怎么做的?

1 个答案:

答案 0 :(得分:14)

您需要创建MKCircle叠加层并将其中心坐标设置为与注释相同。

例如:

//after adding the annotation at "coordinate", add the circle...
MKCircle *circle = [MKCircle circleWithCenterCoordinate:coordinate radius:1000];
[mapView addOverlay:circle];

//implement the viewForOverlay delegate method...    
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay 
{
    MKCircleView *circleView = [[[MKCircleView alloc] initWithOverlay:overlay] autorelease];
    circleView.strokeColor = [UIColor redColor];
    circleView.lineWidth = 2;
    return circleView;
}
相关问题