1

何らかの理由で、コードから都市 (地方) の名前を取得できません。助けてください!

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

2 に答える 2

0

このエラーは通常、構造体のメンバーにアクセスしようとしたときに発生しますが、構造体ではないものにあります。例えば:

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
于 2012-06-04T20:03:28.433 に答える
0

これは比較的古い質問だと思いますが...

私はまったく同じ問題に遭遇し、addressDictionary 目印属性を使用することに頼りました。

[placemark.addressDictionary objectForKey@"City"]

それ以外の

placemark.subAdministrativeArea

後者が機能しない理由もわかりません。

于 2012-03-14T15:49:32.850 に答える