Map Challenge - My approach (Corrections appreciated)


Hi Everyone,

Firstly I would say that the authors have done a commendable job with this Book.

Coming back to the topic, below is how I implemented my third tab for Map challenge.


#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface MapViewController : UIViewController
IBOutlet MKMapView *mv;



#import “MapViewController.h”

@implementation MapViewController

self = [super initWithNibName:nil bundle:nil];
if (self)

    UITabBarItem *tb3 = [self tabBarItem];
     [tb3 setTitle:@"Map"];
    UIImage *tb3i = [UIImage imageNamed:@"rsz_maps.png"];
    [tb3 setImage:tb3i];

return self;


-(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
return [self init];

[super viewDidLoad];
[mv setShowsUserLocation:YES];


-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[mv setRegion:region animated:YES];


if ([mv delegate] == self)
[mv setDelegate:nil];
[mv release];
[super dealloc];

Now my xib file is named MapViewController.xib

I have set the view property to MKMapView and my instance map variable ‘mv’ is also set to MKMapview

Is this the correct approach?

I have a feeling I have some redundancy in my code as I have two pointers to the same MKMapView.

Could I replace ‘mv’ (when I have sent it messages) with MapViewController’s view property as they both point to MKMapView?

Any help would be appreciated.

Thanks once again!