在下面的代码中,我总是从地理编码 NSArray *placemarks 中返回一个对象。我做了一个 NSLog 它总是显示为一个对象。无论我在搜索栏中输入什么。
我正在我的 iPhone 5 设备上对其进行测试。我住在旧金山,设备地图工作得很好。即当我输入“星巴克”时,我只得到一个对象,它被称为“Álvaro Obregón,联邦区 01020” 附近至少有 10 家星巴克。
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[geocoder geocodeAddressString:searchString completionHandler:^(NSArray* placemarks, NSError* error)
if ([placemarks count] > 0) {
NSLog(@"Number of objects in placemarks %i",placemarks.count);
for (CLPlacemark* aPlacemark in placemarks)
{
self.street = aPlacemark.thoroughfare;
self.city = aPlacemark.locality;
self.state = aPlacemark.administrativeArea;
self.zip = aPlacemark.postalCode;
NSMutableString *result = [NSMutableString string];
if (self.street)
[result appendString:self.street];
if (self.street && (self.city || self.state || self.zip))
[result appendString:@", "];
if (self.city)
[result appendString:self.city];
if (self.city && self.state)
[result appendString:@", "];
if (self.state)
[result appendString:self.state];
if (self.zip)
[result appendFormat:@" %@", self.zip];
placemarksArray = [[NSMutableArray alloc]init];
[self.placemarksArray addObject:result];
NSLog(@" This is result %@", result);
[self.searchDisplayController.searchResultsTableView reloadData];
}
}
}
];
return NO;
}