我的代码:
-(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