I'm trying to find the current location and then use the geocoder to find the city,state. This is what I have:
- (void)viewDidLoad
{
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
//NSLog(@"Reverse Geocoder completed");
MKPlacemark * myPlacemark = placemark;
NSString *city = [myPlacemark.addressDictionary objectForKey:(NSString*)kABPersonAddressCityKey];
NSString *state = [myPlacemark.addressDictionary objectForKey:(NSString*)kABPersonAddressStateKey];
location = [[NSString alloc] initWithFormat:@"%@,%@", city, state];
}
I've tested the reverse Geocoder and it works fine when I manually type create a coordinate of my current location: (50.4, -104.6). However, when I run this code with a breakpoint in "didUpdateToLocation" delegate method, the newLocation gives me a coordinate of 37.3,-122.0 which is Cupertino, California. I think I'm setting up the locationManager wrong so any ideas?