I need to draw route between two points and I'm using MKDirectionsRequest
for my purpose.
Getting a route is OK, but I have trouble with drawing it.
In iOS 8 SDK there's no function
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
There is only this one:
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer!
And for some reason, I can't understand why that method isn't called.
Delegate for MapView is set and MapKit is imported.
Here is the rendererForOverlay
function that is implemented:
func rendererForOverlay(overlay: MKOverlay!) -> MKOverlayRenderer! {
println("rendererForOverlay");
var overlayRenderer : MKOverlayRenderer = MKOverlayRenderer(overlay: overlay);
var overlayView : MKPolylineRenderer = MKPolylineRenderer(overlay: overlay);
view.backgroundColor = UIColor.blueColor().colorWithAlphaComponent(0.5);
return overlayView;
}
The map view isn't calling your
rendererForOverlay
method because it is not named correctly.The method must be named exactly:
but in your code it's named:
In addition, you should check that the type of the
overlay
argument isMKPolyline
and set thestrokeColor
of the polyline renderer.(The
view.backgroundColor
in the existing code is actually changing the background color of the view controller'sview
-- not the polyline.)Example: