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

CLGeocoder不工作
EN

Stack Overflow用户
提问于 2012-09-07 14:20:30
回答 2查看 770关注 0票数 0
代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    [window addViewForTouchPriority:viewController.view];

    if(self.locationManager==nil){
        locationManager=[[CLLocationManager alloc] init];

        locationManager.delegate=self;
        locationManager.purpose = @"We will try to tell you where you are if you get lost";
        locationManager.desiredAccuracy=kCLLocationAccuracyBest;
        locationManager.distanceFilter=500;
        self.locationManager=locationManager;
    }
    geoCoder = [[CLGeocoder alloc] init];

    if([CLLocationManager locationServicesEnabled]){
        [self.locationManager startUpdatingLocation];          
    }

    return YES;
}

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    lati = [[NSString alloc] initWithFormat:@"%+.6f", newLocation.coordinate.latitude];
    NSLog(@"address:%@",lati);

    longi = [[NSString alloc] initWithFormat:@"%+.6f", newLocation.coordinate.longitude];
    NSLog(@"address:%@",longi);

    CLLocationCoordinate2D coord;
    coord.latitude = [lati doubleValue];
    coord.longitude = [longi doubleValue];


    [geoCoder reverseGeocodeLocation: newLocation completionHandler: ^(NSArray *placemarks, NSError *error)
     {

         //Get nearby address
         CLPlacemark *placemark = [placemarks objectAtIndex:0];

         //String to hold address
         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];

         //Print the location to console
         NSLog(@"I am currently at %@",locatedAt);

         address = [[NSString alloc]initWithString:locatedAt];    
         NSLog(@"address:%@",address);
     }];
}

我正在使用上面的代码通过给出纬度和经度来获取地址,但是控件没有进入到地理编码器方法中,它跳过了它。有谁能帮我一下吗。

提前谢谢。

EN

回答 2

Stack Overflow用户

发布于 2012-10-03 19:40:45

不要紧,控制不进入方法,但它可以工作,注意它将工作的输出。

票数 0
EN

Stack Overflow用户

发布于 2013-10-06 00:35:42

这很正常,因为reverseGeocodeLocation中的代码是在一个块中执行的。块中代码的执行发生在另一个线程中,所以不会在主线程中执行,这就是为什么控件不会进入地理编码器方法的原因。

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

https://stackoverflow.com/questions/12312755

复制
相关文章

相似问题

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