I 've been trying to add a half circle to a map view using a custom MKOverlayPathView subclass and a custom class which confirms to but I cannot get anything to show up on the map view. I use a UIBezierPath to create the path for the circle, but no matter what I try, I cannot see my path... Does anyone have an example program in which a UIBezierPath is being used as overlay?
Thank you!
Tim
Edit: Answer to Anna's question:
I can draw MKCircleViews without any problem, but I seem to struggle with custom subclasses for MKOVerlay(Path)View. The delegate is set, and an NSLog confirms that my overlay is actually added, only the View part is missing ...
Below the header file for my overlay class. Comments and variables are in Dutch, if anyone wants a translation I can provide it but I think everything should be clear. I create a overlay with centre coordinate and radius.
The boundingMapRect is calculated from the centre coordinate. Origin is centre minus the radius for both x and y, and the width + height are twice the radius.
@interface PZRMijnOverlay : NSObject <MKOverlay>
{
}
//een property die een bezierpath beschrijft, naar de 2 standaard overlay properties
@property (nonatomic, strong) UIBezierPath *bezierPath;
@property (nonatomic) CLLocationDistance straal;
//class method
+(PZRMijnOverlay *)bezierCirkelMetCenterCoordinate: (CLLocationCoordinate2D)coordinaat enStraal: (CLLocationDistance)eenStraal;
//een eigen designated init
-(id)initWithCenterCoordinate: (CLLocationCoordinate2D)coordinaat enStraal: (CLLocationDistance)eenStraal;
@end
This is de viewForOverlay method implementation:
PZROverlayView *overlayView = [[PZROverlayView alloc] initWithOverlay:(PZRMijnOverlay *)overlay];
overlayView.strokeColor = [UIColor redColor];
overlayView.lineWidth = 10;
//overlayView.strokeColor = [UIColor blackColor];
return overlayView;
Now I guess I should overwrite the createPath method in my PZROverlayView class, but I cannot figure out what code needs to go there. What I tried was to create a UIBezierPath, convert it to CGPath and assign it to the path property of the MKOverlayPathView super class.