bloggandomene

elbryan's blog

MapKitDynRoutes: Handle iOS4 routes dynamically

Posted by elbryan Tue, 20 Jul 2010 11:12:00 GMT

Since iPhone iOS4 has released I’ve been working on the new features brought by the new version of the OS.
One of the most useful thing (to me) introduced by iOS4 is the capability of drawing routes directly on the map using public APIs.
How that works is fairly simple: given two or more coordinates it generates a Polyline and put it on the map. This line automagically rescales/resizes in order to maintain the correct aspect even when zooming/panning.

Unfortunately, this new object doesn’t allow developers to update the line with new points. The only thing you can do is to destroy the line, remove the overlay from the map, recreate a line with all previous points plus the new one, generate the respective line associated with the map and add it (as overlay) on the map itself. This is quite a waste of CPU cycles.

I’ve written a set of two classes that tries to handle the Polyline growth automatically.

The project is called MapKitDynRoutes and the libraries are FFMapRoute and FFMapRoutes.

MapKitDynRoutes is shipped with a Demo project that shows how to use the library. It contains, furthermore, a small object FFLocationManager that simulates the GPS behaviour by injecting coordinates to the application using a timer and reading those from a CSV file.

MapKitDynRoutes is released under MIT license.


Posted in , | Tags , , | no comments |