Routes/Lines on a MKMapView
(as a MKAnnotationView) – Part 2.5
by Hans Pinckaers
Download available after the jump.
First, I should credit Craig for his example of drawing lines on a MKMapView (http://spitzkoff.com/craig/?p=108), that’s where you can find part 1 and part 2. This post is a teaser of what I am going to post later this month. It’s a improvement on his code and makes overlays on a MKMapView possible without the need to hide it when zooming/panning around.
The performance is pretty good. There is absolutely no lag on the iPhone 3GS, you will notice that panning/zooming around on the iPhone 3G is not that smooth as on the 3GS, but it’s acceptable.
I will publish it here on my blog when my app update is ready and Apple approved it. Will be in a month or so. If you actually found a way of doing this please let me now, I still looking for other ideas.
–
Download
I do not have a lot of time to write a big blogpost, so I’m just going to post the code, and maybe later write the explanation.
Looks really nice man. I’ve been tinkering with trying to solve the same problem over the last few days and this seems solid. Thanks for posting!
Hi Hans,
Nice work! I’ve got a question though. It’s got more to do with the Craig’s codebase, but maybe you can shed some light on it.
What I’m trying to do is to display an evolving route. Most of it’s static but the last coordinate is extrapolated based (as if something is moving at a certain speed). I am trying to accomplish this with two routes – one for the static component and one for the extrapolated bit.
The problem I’m having is that the RouteView is initializing with a non-origin frame which is causing the extrapolated route to get cropped in certain situations. And because I keep redrawing/extrapolating this every second, it gets re-cropped every second.
Do you have an idea on how to get the RouteView to initialize correctly, i.e. aligned with the frame of the mapview?
With iOS4 it’s better to use build in MapView overlays.
Do you know of it’s worthwhile to
use MKOverlayPathView in iOS4? It seems to me you still have
to define the path yourself with this class (ie – figure out how to
match the route to the roads on the maps).
At least in iOS4 the route is not updating while zooming.
Great work, thanks for sharing
Great work i was searching alot for this work and it help me alot in my application so thanks alot