LeanneGamble LeanneGamble - 4 months ago 33
iOS Question

Using viewForOverlay to return an MKOverlayView but I also need to return an MKCircleRenderer in the same method

I have an

that I need to display two types of overlay on. One is a tiled overlay that I use a subclass of
and an

My method is:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
but now I need to also render an
I'm getting an compiler error of:
'Incompatible pointer types returning 'MKCircleRenderer *' from a function with result type 'MKOverlayView * _Nonnull'.

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay

if ([overlay isKindOfClass:[MKCircle class]]) {
MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circleView.strokeColor = [UIColor redColor];
circleView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.4];
return circleView;
} else {
TileOverlayView *view = [[TileOverlayView alloc] initWithOverlay:overlay];
view.tileAlpha = 1.0;
return view;

That is my code, I'm aware that
is deprecated which I'm working on as another issue.

Rob Rob

The issue is that the tile view is apparently subclassing from MKOverlayView (returned by viewForOverlay), whereas MKCircleRenderer subclasses from the more modern MKCircleRenderer, a subclass of MKOverlayRenderer (returned by rendererForOverlay), not of MKOverlayView.

If you can make your tile view a MKOverlayRenderer subclass rather that an overlay view, then you can implement rendererForOverlay and return either circle renderer views or tile view rather than viewForOverlay.