Skip to content
Objective-C classes for drawing lines from a series of points in an MKMapView.
Latest commit 5df28c1 May 5, 2010 @gdavis gdavis updated documentation
Failed to load latest commit information.
MapRoutes.xcodeproj general cleanup and commenting to prep for first release May 5, 2010
.gitignore updated ignores May 5, 2010
MainWindow.xib added inital contents May 4, 2010
MapRoutes-Info.plist added inital contents May 5, 2010
MapRoutesViewController.xib added inital contents May 5, 2010
MapRoutes_Prefix.pch added inital contents May 5, 2010
README.rdoc updated documentation May 5, 2010
main.m added inital contents May 5, 2010



MapRoutes is a set of Objective-C classes that simplifies drawing and placing routes in an MKMapView. MapRoutes is designed to work with iPhone OS 3.2 and higher.

These classes provide a framework for easily adding routes and takes care of cropping, positioning, and toggling the route's visibility when zooming/panning.


• MapRoutesViewController - The view controller which sets up the MKMapView, the FMapRoute, and FMapRouteLine. Also acts as an MKMapViewDelegate to tell the route when the map region has been updated and to provide the view for the route annotation.

• FMapRoute - This class adopts the MKAnnotation protocol and extends MKAnnotationView. The FMapRoute does not perform the line drawing itself, but instead needs an instance of FMapRouteLine to be set as its lineView. FMapRoute is an MKAnnotationView so that it can handle the placement of the FMapRouteLine as a subview.

• FMapRouteLine - Base class for drawing and styling the line for the route. Subclass this method and override the drawRect: method to implement custom line drawing.

• FMapRouteDottedLine - An example subclass of FMapRouteLine which draws a dotted line instead of a solid line.

Example Usage

- (void)viewDidLoad {

// create map view _map = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; [_map setMapType:MKMapTypeSatellite]; [_map setShowsUserLocation:YES]; [_map setDelegate:self]; [self setView:_map];

// create points _points = [[NSMutableArray alloc] init];

// glendale CLLocation* loc = [[CLLocation alloc] initWithLatitude:39.706835 longitude:-104.93093]; [_points addObject:loc]; [loc release];

// the office loc = [[CLLocation alloc] initWithLatitude:39.718903 longitude:-104.95326]; [_points addObject:loc]; [loc release];

// mile-high stadium loc = [[CLLocation alloc] initWithLatitude:39.744511 longitude:-105.020699]; [_points addObject:loc]; [loc release];

// create route annotation and init _route = [[[FMapRoute alloc] initWithPoints:_points andFrame:CGRectMake(0, 0, 320, 480)] autorelease]; [_map addAnnotation:_route];

// add a dotted line FMapRouteDottedLine *line = [[FMapRouteDottedLine alloc] initWithRoute:_route withMap:_map];

// assign the view that draws the line to the route [_route setLineView:line];

[line release];

// center on the region [_map setRegion:[_route region]];

[super viewDidLoad]; }

Something went wrong with that request. Please try again.