在下面的代码中,我总是只从地理编码NSArray *地标中获取一个Object。我做一个NSLog,它总是显示为一个对象。无论我在searchBar中输入什么。
我正在iPhone 5设备上测试它。我住在旧金山,设备地图工作得很好。即当我输入'星巴克'时,我只得到一个对象,它被称为“ÁlvaroObregó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;
}