newLocation logging is infinite loop and iOS Simulator Quest


#1

I believe I copied the code exactly from the book, I pasted my WhereamiViewController.h and .m files below.

When I ran the application the first time, the iOS simulator started and the iPhone display came up with a prompt for my location. I allowed it and then the NSLog(@"%@",newLocation)
started printing to the console and kept printing-

I have to stop the program to exit the loop. The program never ends on itself. If that is expected, I’d expect it to be mentioned in the book. I tried debugging at the NSLog code point but I can’t interpret much from the output-

[code]//
// WhereamiViewController.h
// Whereami
//
// Created by user2664 on 6/27/13.
// Copyright © 2013 user2664. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface WhereamiViewController : UIViewController
{
CLLocationManager *locationManager;
}

@end
[/code]


[code]//
// WhereamiViewController.m
// Whereami
//
// Created by user2664 on 6/27/13.
// Copyright © 2013 user2664. All rights reserved.
//

#import “WhereamiViewController.h”

@implementation WhereamiViewController

  • (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
    self = [super initWithNibName:nibNameOrNil
    bundle:nibBundleOrNil];

    if (self) {
    // create location manager object
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];

      // accurate as possible
      // regardless of time or power
      [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
      
      // look for location immediately
      [locationManager startUpdatingLocation];
    

    }
    return self;
    }

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

-(void)dealloc
{
[locationManager setDelegate:nil];
}
@end[/code]


#2

Did you mean?

NSLog (@"%@", newLocation)

% is missing in yours.


#3

Sorry, typo in my post entry. I have fixed. I still have the same issue.


#4

This is happening to me to after following the instructions with the new Locations methods.

It keeps logging the same location with different times associated with the location. Seems like the method locationManager:didUpdateLocations keeps getting called every second.

Is this supposed to happen?

Did you figure it out?


#5

It stopped continuously logging once I set the Distance filter.