0
- (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);
     }];
}

我使用上面的代码通过给出纬度和经度来获取地址,但是控制没有进入地理编码器方法,它跳过它。任何人都可以帮助我。

提前致谢。

4

2 回答 2

0

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

于 2013-10-05T16:35:41.973 回答
0

没关系,控件没有进入方法,但它可以工作,注意输出它会工作。

于 2012-10-03T11:40:44.860 回答