我正在尝试将位置搜索列表显示到 TableView 中,首先这可能吗?
如果是这样,我会怎么做?
我收集列表的代码是:
MKLocalSearchRequest *searchRequest = [[MKLocalSearchRequest alloc] init];
[searchRequest setNaturalLanguageQuery:@"Cafe"];
CLLocationCoordinate2D userCenter = CLLocationCoordinate2DMake(48.8566, 2.3522);
MKCoordinateRegion userRegion = MKCoordinateRegionMakeWithDistance(userCenter, 15000, 15000);
[searchRequest setRegion:userRegion];
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:searchRequest];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
if (!error) {
NSMutableArray *gLoc = [NSMutableArray array];
for (MKMapItem *mapItem in [response mapItems]) {
[gLoc addObject:mapItem.placemark];
NSLog(@"Name: %@, Placemark title: %@", [mapItem name], [[mapItem placemark] title]);
在上面的示例中,我在巴黎搜索“Cafe”,并将信息存储到一个名为 gLoc 的数组中。
的内容:
NSLog(@"Name: %@, Placemark title: %@", [mapItem name], [[mapItem placemark] title]);
是所有位置的完整列表,格式如下:
Name: Strada Café, Placemark title: 94 Rue du Temple, 75003 Paris, France
的内容:
NSLog(@"%@", gLoc);
是所有位置的数组,格式为:
"Strada Caf\U00e9, 94 Rue du Temple, 75003 Paris, France @ <+48.86220020,+2.35731150> +/- 0.00m, region CLCircularRegion (identifier:'<+48.86220020,+2.35731150> radius 49.91', center:<+48.86220020,+2.35731150>, radius:49.91m)",
我很困惑如何继续。理想情况下,我希望将此信息转换为名称作为标题和地址作为副标题,有没有办法以这种方式操纵数据来实现这一点?