由于某些原因,我无法从我的代码中获取城市(地区)的名称。请帮帮我!
- (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;
}发布于 2012-03-14 23:49:33
我知道这是一个相对陈旧的问题,但是...
我遇到了完全相同的问题,并求助于使用addressDictionary placemark属性,例如,
[placemark.addressDictionary objectForKey@"City"]而不是
placemark.subAdministrativeArea我不明白为什么后者也不能工作。
发布于 2012-06-05 04:03:28
当您试图访问结构的成员,但访问的对象不是结构时,通常会出现此错误。例如:
struct {
int a;
int b;
} foo;
int fum;
fum.d = 5;如果你试图在有指针的情况下访问一个实例,也会发生这种情况,反之亦然。例如:
struct foo {
int x, y, z;
};
struct foo a, *b = &a;
b.x = 12; /* This will generate the error, it should be b->x or (*b).x */如果执行以下操作,它也会出现:
struct foo { int x, int y, int z }foo;
foo.x=12而不是:
struct foo { int x; int y; int z; }foo;
foo.x=12因为这样,你就会得到一个看起来像是在处理实例的代码,而实际上它是在处理指针。
在我看来,你需要检查一下你的代码。也许,试试这个:
NSString *strLocation = (NSString *)placemark.locality; // Get localityhttps://stackoverflow.com/questions/7304022
复制相似问题