首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用MKLocalSearch在MKMap中搜索地址

如何使用MKLocalSearch在MKMap中搜索地址
EN

Stack Overflow用户
提问于 2014-12-06 22:54:29
回答 1查看 672关注 0票数 2

我试着用MKLocalSearch搜索地址,但只找到了商业地址,而不是确切的地址,比如苹果的地图(苹果的应用程序)。

我希望你们能帮助我-谢谢!:)

代码语言:javascript
复制
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = query;
request.region = self.mapView.region;

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.localSearch = [[MKLocalSearch alloc] initWithRequest:request];

[self.localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error){

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

    if (error != nil) {
        [[[UIAlertView alloc] initWithTitle:@"Map Error"
                                    message:[error description]
                                   delegate:nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil] show];
        return;
    }

    self.results = response;

`

EN

回答 1

Stack Overflow用户

发布于 2015-06-06 00:10:02

在结果数组中,类型为MKMapItem,您需要配置单元格,以便在tableView出现时为您提供地址。这里有一个简单的例子。

代码语言:javascript
复制
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let IDENTIFIER = "CellID"
    let cell = tableView.dequeueReusableCellWithIdentifier(IDENTIFIER, forIndexPath: indexPath) as! UITableViewCell

    // Configure the cell...
    var item: MKMapItem = results[indexPath.row]

    cell.textLabel?.text = item.placemark.name
    cell.detailTextLabel?.text = item.placemark.addressDictionary["Street"] as? String

    return cell
}

这都是在属于UITableViewDataSource协议的cellForRowAtIndexPath方法中完成的。

希望这对你有所帮助,并祝你好运!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27332902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档