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?
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;
}