ios – 减去两个MKCircle或如何在MapKit中的地图上绘制一个环?

我正在尝试在MapKit中为地图添加环形叠加层.

我可以从另一个MKCircleView中减去一个MKCircleView,还是需要编写自己的自定义叠加?

最佳答案 对于图片中的环类,您无需创建自定义叠加层.

要绘制基本环,请添加单个MKCircle,对于其MKCircleView,请根据所需的环厚度设置lineWidth.

//Create the MKCircle (could be in viewDidLoad)...
MKCircle *c = [MKCircle circleWithCenterCoordinate:
                  CLLocationCoordinate2DMake(someLat, someLong) 
                  radius:2000];
[myMapView addOverlay:c];


//In viewForOverlay delegate method, return a MKCircleView...
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
    if ([overlay isKindOfClass:[MKCircle class]])
    {
        MKCircleView *cv = [[MKCircleView alloc] initWithCircle:overlay];
        cv.lineWidth = 15;  // <-- controls thickness of ring
        cv.strokeColor = [UIColor greenColor];
        cv.alpha = 0.75;
        return cv;
    }

    return nil;
}
点赞