4

I am trying to add a ring overlay to a map in MapKit.

Can I subtract one MKCircleView from another MKCircleView or do I need to code my own custom overlay?

enter image description here

TimoP
  • 51
  • 3

1 Answers1

2

For the kind of ring in the picture, you don't need to create a custom overlay.

To draw a basic ring, add a single MKCircle and for its MKCircleView, set the lineWidth based on how thick a ring you want.

//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;
}
  • I think it's points but essentially yes. It is scaled automatically based on the zoom level. –  Apr 02 '12 at 16:41
  • Ok, thank you. I need for example an area of 10m width in 30m distance to a point on the map. I try this. – TimoP Apr 02 '12 at 17:00