我试着用MKLocalSearch搜索地址,但只找到了商业地址,而不是确切的地址,比如苹果的地图(苹果的应用程序)。
我希望你们能帮助我-谢谢!:)
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;`
发布于 2015-06-06 00:10:02
在结果数组中,类型为MKMapItem,您需要配置单元格,以便在tableView出现时为您提供地址。这里有一个简单的例子。
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方法中完成的。
希望这对你有所帮助,并祝你好运!
https://stackoverflow.com/questions/27332902
复制相似问题