首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CLGeocoder什么都不回

CLGeocoder什么都不回
EN

Stack Overflow用户
提问于 2012-06-08 11:13:45
回答 1查看 1.7K关注 0票数 0

我正在尝试使用一个iPhone和CLGeocoder来确定CLLocationManager用户的位置。

我的CLLocationManager似乎工作得很好,但不幸的是,CLGeocoder并没有做我希望它做的事情。

一些代码摘录:

代码语言:javascript
复制
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    [self.locationManager stopUpdatingLocation];

    NSLog(@"Location updated to: %@",newLocation);

    [self.geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {

        NSLog(@"Reverse geocoding finished");

        self.currentPlacemark = [placemarks objectAtIndex:0];
        NSLog(@"%@",self.currentPlacemark.locality);
        NSLog(@"%@",self.currentPlacemark.ISOcountryCode); 

    }];
}

- (void)getCurrentLocation {

    NSLog(@"Determining current location");

    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;

    [self.locationManager startUpdatingLocation];
}

- (void)viewDidLoad {

    [super viewDidLoad];
    [self getCurrentLocation];
}

self.currentPlacemark是一个CLPlacemark对象。

self.geocoder是一个CLGeocoder对象。

self.locationManager是一个CLLocationManager对象。

我遗漏了什么?为什么这不管用?我真的花了几个小时慢慢地开始变得绝望的…

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-08 11:24:15

是的,你应该分配和插入你的地理编码器。

代码语言:javascript
复制
self.geocoder = [[[CLGeocoder alloc] init] autorelease];
[self.geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {

    NSLog(@"Reverse geocoding finished");

    self.currentPlacemark = [placemarks objectAtIndex:0];
    NSLog(@"%@",self.currentPlacemark.locality);
    NSLog(@"%@",self.currentPlacemark.ISOcountryCode); 

}];
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10947762

复制
相关文章

相似问题

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