Мой код:
-(void)addressLocation:(NSArray *)inputData {
NSString *plusAddress = [[inputData objectAtIndex:0] stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@,%@&sensor=false®ion=pl", plusAddress, [inputData objectAtIndex:1]]];
__block CLLocationCoordinate2D newRecord;
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSArray *results = [JSON valueForKey:@"results"];
NSNumber *latNumber = [[results objectAtIndex:0] valueForKeyPath:@"geometry.location.lat"];
NSNumber *lngNumber = [[results objectAtIndex:0] valueForKeyPath:@"geometry.location.lng"];
CGFloat lat = [latNumber floatValue];
CGFloat lng = [lngNumber floatValue];
newRecord = CLLocationCoordinate2DMake(lat, lng);
} failure:nil];
[operation start];
[operation waitUntilFinished];
KantorPoint *newPoint = [[KantorPoint alloc] init];
newPoint.coordinate = newRecord;
newPoint.name = [inputData objectAtIndex:1];
newPoint.address = [inputData objectAtIndex:0];
[self.pointersArray addObject:newPoint];
}
Я пытаюсь передать newRecord
из операционного блока, как в этом ответе. Но newPoint.coordinate
это null
и я не могу сделать что-то вроде return newRecord
внутри блока (получить ошибку). Есть ли способ решить эту проблему?
failure
при созданииoperation
. Сделайте это и посмотрите, вызовут ли его. - person Nate   schedule 08.07.2012NSLog(@"newRecord lat = %f",newRecord.latitude);
консоль показывает мне правильное значение. - person RomanHouse   schedule 08.07.2012