Reputation: 105
I have been doing iOS dev for a few months. I already have a map view with a couple of annotations pinned to it and can show the users current location.
I haven been trying to read through the docs to implement a simple overlay using a set of CLLocationCoordinate2D to draw out a line (simple static route). Its has been a struggle
My MkOverlayRenderer method doesnt seem to be running at all. If I am not mistaking i shouldn't need the MKMapViewDelegate. I am trying to implement MKOverlay delegate and have "@synthesize boundingMapRect;".
Here is my code for trying to implement the Overlay
- (void)drawLineRoute
{
CLLocationCoordinate2D purplePoints[2];
purplePoints[0] = CLLocationCoordinate2DMake(28.541944, -81.382936);
purplePoints[1] = CLLocationCoordinate2DMake(28.538447, -81.383096);
MKPolyline *purplePolyline = [MKPolyline polylineWithCoordinates:purplePoints count:2];
purplePolyline.title = @"Citrus Bowl Connection";
[self.mapView addOverlay:purplePolyline];
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView viewForOverlay: (id<MKOverlay>)overlay
{
if([overlay isKindOfClass:[MKPolyline class]])
{
MKPolygonRenderer *polyRender = [[MKPolygonRenderer alloc] initWithOverlay:overlay];
polyRender.lineWidth = 2;
polyRender.strokeColor = ovoPurple;
return polyRender;
}
return nil;
}
Any help or guidance is greatly appreciated. Thank you all in advance.
Upvotes: 2
Views: 984
Reputation: 437372
There are two different delegate methods:
mapView:rendererForOverlay:
, which was introduced in iOS 7, and returns a MKOverlayRenderer
; and
mapView:viewForOverlay:
, which was deprecated in iOS 7, but it returns a MKOverlayView
, not a MKOverlayRenderer
.
It is incorrect to implement a viewForOverlay
that returns a MKOverlayRenderer
.
Bottom line, if you need to support iOS versions prior to iOS 7, implement viewForOverlay
that returns a MKOverlayView
, not a MKOverlayRenderer
. If you don't need to support iOS versions prior to 7, then do not implement viewForOverlay
at all, but rather implement rendererForOverlay
that returns a MKOverlayRenderer
.
Upvotes: 1