首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKReverseGeocoder的问题

MKReverseGeocoder的问题
EN

Stack Overflow用户
提问于 2011-09-05 12:57:50
回答 2查看 418关注 0票数 1

由于某些原因,我无法从我的代码中获取城市(地区)的名称。请帮帮我!

代码语言:javascript
复制
 - (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;
        }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-14 23:49:33

我知道这是一个相对陈旧的问题,但是...

我遇到了完全相同的问题,并求助于使用addressDictionary placemark属性,例如,

代码语言:javascript
复制
[placemark.addressDictionary objectForKey@"City"]

而不是

代码语言:javascript
复制
placemark.subAdministrativeArea

我不明白为什么后者也不能工作。

票数 0
EN

Stack Overflow用户

发布于 2012-06-05 04:03:28

当您试图访问结构的成员,但访问的对象不是结构时,通常会出现此错误。例如:

代码语言:javascript
复制
struct {
    int a;
    int b;
} foo;
int fum;
fum.d = 5;

如果你试图在有指针的情况下访问一个实例,也会发生这种情况,反之亦然。例如:

代码语言:javascript
复制
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 */

如果执行以下操作,它也会出现:

代码语言:javascript
复制
struct foo {   int x, int y, int z }foo; 
foo.x=12

而不是:

代码语言:javascript
复制
struct foo {   int x; int y; int z; }foo; 
foo.x=12

因为这样,你就会得到一个看起来像是在处理实例的代码,而实际上它是在处理指针。

在我看来,你需要检查一下你的代码。也许,试试这个:

代码语言:javascript
复制
NSString *strLocation = (NSString *)placemark.locality; // Get locality
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7304022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档