I am using CLLocationManager
on device and the delegate methods aren't getting called. Here's my code (I can see that the class isn't getting deallocated either):
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface CurrentLocation : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
#import "CurrentLocation.h"
#import "SBJson.h"
@implementation CurrentLocation
@synthesize locationManager;
- (id)init
{
self = [super init];
if (self) {
NSLog(@"Initialized");
locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
BOOL enable = [CLLocationManager locationServicesEnabled];
NSLog(@"%@", enable? @"Enabled" : @"Not Enabled");
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(@"A");
NSString *stringURL = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=true", newLocation.coordinate.latitude, newLocation.coordinate.longitude];
NSLog(@"%@", stringURL);
NSURL *url = [NSURL URLWithString:stringURL];
NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url] returningResponse:nil error:nil];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *dict = [parser objectWithData:data];
NSLog(@"%@", dict);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"B");
}
- (void)dealloc {
NSLog(@"Dealloc called");
[super dealloc];
[locationManager release];
}
@end
In log, I see:
2011-10-02 19:49:04.095 DixieMatTracker[1404:707] Initialized
2011-10-02 19:49:04.109 DixieMatTracker[1404:707] Enabled
What am I doing wrong? Thanks