1

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.

  • Can you post the custom MKOverlayPathView code? If you add a regular MKCircle/MKCircleView, does that overlay display? Is the map view's delegate set? Are the coordinates of the half-circle correct? Is the boundingMapRect property correct? –  Aug 22 '12 at 12:58
  • You might want to consider the following explanation: https://stackoverflow.com/a/61573384/4260691 – OhadM May 03 '20 at 11:06

1 Answers1

1

Alright, I finally found what I was doing wrong! It is actually way easier than I thought!

Solution:

  1. Add MKCircle overlay
  2. In viewForOverlay: create a bezierPath (CG or UI) and add it to the path property of a standard MKOverlayPathView instance

I was making it myself way too difficult by using custom classes...

  • I am having the same problem but can't get my MKCircle overlay to work :( Would u be able to provide any code for this answer? – Sarah92 Mar 15 '14 at 14:27