出于某种原因,我无法从我的代码中获取城市(地区)的名称。请帮忙!
- (void)viewDidLoad {
[super viewDidLoad];
self.lm = [[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
lm.distanceFilter = kCLDistanceFilterNone;
[lm startUpdatingLocation];
}
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *) newLocation fromLocation: (CLLocation *)oldLocation {
if (!geocoder) {
geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
geocoder.delegate = self;
[geocoder start];
}
NSString *lat = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.latitude];
NSString *lng = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.longitude];
NSString *acc = [[NSString alloc] initWithFormat:@"%f", newLocation.horizontalAccuracy];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:lat message:lng delegate:self cancelButtonTitle:acc otherButtonTitles: @"button", nil];
[alert show];
[alert release];
[lat, lng, acc release];
}
- (void) reverseGeocoder:(MKReverseGeocoder *)geo didFailWithError:(NSError *)error {
[geocoder release];
geocoder = nil;
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geo didFindPlacemark:(MKPlacemark *)placemark {
**THIS IS WHERE THE ERROR IS OCCURRING** (REQUEST FOR MEMBER 'LOCALITY' IN SOMETHING NOT A STRUCTURE OR UNION)
location = [NSString stringWithFormat:@"%@", placemark.locality];
[geocoder release];
geocoder = nil;
}