Проблема с MKReverseGeocoder - PullRequest
       32

Проблема с MKReverseGeocoder

1 голос
/ 05 сентября 2011

По какой-то причине я не могу получить название города (населенного пункта) из своего кода.Пожалуйста, помогите!

 - (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;
        }

Ответы [ 2 ]

0 голосов
/ 05 июня 2012

Эта ошибка обычно возникает, когда вы пытаетесь получить доступ к элементу структуры, но к чему-то, что не является структурой.Например:

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 locality
0 голосов
/ 14 марта 2012

Я понимаю, что это довольно старый вопрос, но ...

Я столкнулся с точно такой же проблемой и прибегнул к использованию атрибута метки addressDictionary, например,

[placemark.addressDictionary objectForKey@"City"]

вместо

placemark.subAdministrativeArea

Я не понимаю, почему последний тоже не работает.

...