Map View Challenge


When I run the application, the map displays where I am, but does not zoom. Any suggestions?

[code]#import “MapViewController.h”

@implementation MapViewController

// Call the superClass’ designated initializer
[super initWithNibName:@"MapViewController"

// Get the tab bar item
UITabBarItem *tbi = [self tabBarItem];

// Give it a label
[tbi setTitle:@"Map"];

UIImage *i = [UIImage imageNamed:@"Hypno.png"];
[tbi setImage:i];

locationManager = [[CLLocationManager alloc] init];

return self;


  • (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
    // Disregard parameters - nib name is an implementation detail
    return [self init];

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

  • (void)viewDidLoad {
    [super viewDidLoad];
    [locationManager setDelegate:self];
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [mapView setShowsUserLocation:YES];


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

  • (void)didReceiveMemoryWarning {
    // Releases the view if it doesn’t have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren’t in use.

  • (void)viewDidUnload {
    [super viewDidUnload];
    [mapView release];
    mapView = nil;
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

  • (void)dealloc {
    if([locationManager delegate] == self)
    [locationManager setDelegate:nil];
    [locationManager release];

    [mapView release];
    [super dealloc];




The header file is not shown. Does it note that MapViewController conforms to the CLLocationManagerDelegate and MKMapViewDelegate protocols?


It does


In the .xib, can you verify the MapView’s delegate is connected to File’s Owner?


Did you setdelegate for the mapview somewhere as in below?

[mapView setDelegate:self];