Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclassing MKOverlayPathView to create MKPolylineView

Tags:

ios

mapkit

Has anyone attempted to subclass MKOverlayPathView in order to, essentially, recreate MKPolylineView with more control of the path drawing? If so, would you be willing to share some example code?

I want to draw an MKPolyline on a map view but MKPolylineView does not offer enough flexibility in how the path is drawn. For instance I want to add a stroke and highlight on the line like the routes seen in the Maps app.

enter image description here

like image 373
mark Avatar asked Sep 27 '12 02:09

mark


1 Answers

I came across this today when I was looking for a way to draw a border around an MKPolylineView. After a bit of research and digging around, I created my own simple subclass of MKOverlayPathView which works as a drop-in replacement of MKPolylineView and adds support for drawing a border.

It ended up being very simple, you can take a look at the sample code on GitHub ASPolylineView or take a look at my brief blog post describing the main things that need to be done. It's a good building block to get started with more advanced custom drawing. For a more sophisticated subclass of MKOverlayPathView, take a look at AIMapViewWrapper - especially the AIOverlayRouteView class.

like image 171
Adrian Schönig Avatar answered Oct 31 '22 21:10

Adrian Schönig