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

それは問題ではありません。制御はメソッドに入力されませんが、機能します。機能する出力に注意してください。

于 2012-10-03T11:40:44.860 に答える
0

reverseGeocodeLocation 内のコードはブロック内で実行されるため、これは正常です。ブロック内のコードの実行は別のスレッドで発生するため、メイン スレッドでは実行されません。これが、コントロールがジオコーダー メソッド内に入らない理由です。

于 2013-10-05T16:35:41.973 に答える