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

Oks*_*ana 6 iphone sdk xcode objective-c

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

我会假设这是某种形式的MKAnnotation,但我在文档中找不到任何解释这一点的内容.有谁知道这是怎么做的?

小智 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;
}
Run Code Online (Sandbox Code Playgroud)