Going to the Current Location
Although you require the user to pan to the user location on the map if he or she wants to see it, it’s kind of annoying in this particular case unless you’re actually coding this in or around New York City. To remove at least that annoyance from your life, I show you how easy it is to add a button to the Navigation bar to zoom in to the current location and then back to the map region and span you’re currently displaying.
Add the bolded code in Listing 17-21 to add the button in the MapController
method viewDidLoad
.
Listing 17-21: Updating viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.delegate = self;
mapView.showsUserLocation = YES;
[self setInitialRegion];
RTAppDelegate* appDelegate = [[UIApplication
sharedApplication] delegate];
if ([[UIDevice currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPad) {
UILabel * titleLabel = [[UILabel alloc]
initWithFrame:CGRectMake (0,0,250,44)];
titleLabel.textColor = [UIColor yellowColor];
titleLabel.font = [UIFont boldSystemFontOfSize:17];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = [self mapTitle];
UIBarButtonItem *titleView = [[UIBarButtonItem alloc]
initWithCustomView:titleLabel];
UIBarButtonItem *flexibleSpace=
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
flexibleSpace.width = 1.0;
NSMutableArray *itemsArray = ...
Get iPad Application Development For Dummies, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.