No zoom, animation, or even blue location dot


#1

As the title says, I’m at the point in the book right prior to adding annotations. My code, however, is not producing any zoom, animation, or location dots. It only shows the map of north america. I have tried the debuging written by Joe here:
viewtopic.php?f=217&t=4397
But it provided no solution. :neutral_face:

There is no error messages or anything. When I try to simulate an location in the debugger, nothing happens too.

Below I have listed my code, any help is appreciated and thank you, in advance!

WhereamiViewController.h

[code]#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface WhereamiViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>
{
CLLocationManager *locationManager;

IBOutlet MKMapView *worldView;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet UITextField *locationTitleField;

}
[/code]

WhereamiViewController.m

[code]#import “WhereamiViewController.h”

@implementation WhereamiViewController

  • (void)viewdidload
    {
    [worldView setShowsUserLocation:YES];
    }

  • (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
    {
    NSLog(@"%@", worldView);
    //but how do we actually zoom now that we know when to zoom?
    CLLocationCoordinate2D loc = [userLocation coordinate];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
    [worldView setRegion:region animated:YES];
    NSLog(@"%@", worldView);

}

  • (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
    self = [super initWithNibName:nibNameOrNil bundle: nibBundleOrNil];
    if (self) {
    // create location manager object

      locationManager = [[CLLocationManager alloc] init];
      
      // there will be a warning from this line of code, ignore it for now
      [locationManager setDelegate:self];
      
      // and we want to be as accurate as possible regardless of how much time/ power it takes
      [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
      
      // tell our manager to start looking for its location immediately
      //[locationManager startUpdatingLocation]; - no longer needed as Mapkit will start to calculate locaiton as soon as launched.
    

    }

return self;
}

  • (void)locationManager: (CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
    NSLog(@"%@", newLocation);

}

  • (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
    NSLog(@“Could not find location: %@”, error);
    }

-(void) dealloc
{
// tell the location manager to stop sending us messages
[locationManager setDelegate:nil];
}

@end
[/code]


#2

Solution found.

It seems in MKMapView, under behaviour, the “Show User Location” box was unchecked in the Attribute inspector.

If you are having similar troubles, check that box! :smiley:


#3

However this property is supposed to be setup when you declare:

  • (void)viewDidAppear
    {
    [worldView setShowsUserLocation:YES];
    }

Why it doesn’t work? maybe it is needed to set it within an init method


#4

Hi, I did all the changes I’ve found in the forum, but nothing happens…
Build and run are ok, North America appears, I can write a name of any cities in the world (say “Pris, France”), but the Done button doesn’t seam to have any function.
It’s strange that such an important code was forgotten in the book. What am I missing???
Help!!!


#5

I don’t have any answer, but I do have the same question. My blue dot does appear but the screen doesn’t zoom and my enter button does not resignFirstResponder;
I will keep looking. I am thinking it is because I’m working in Xcode 5 but am note sure. Was there ever an answer posted for this?