Skip to content

Instantly share code, notes, and snippets.

@hanawat
Created March 30, 2016 02:47
Show Gist options
  • Save hanawat/5bee80f6dc0ed9ded4bde93d278a4b9f to your computer and use it in GitHub Desktop.
Save hanawat/5bee80f6dc0ed9ded4bde93d278a4b9f to your computer and use it in GitHub Desktop.
iOS9.3で追加されたMKLocalSearchCompleterを試す ref: http://qiita.com/hanawat/items/1f3f3c277a8f2c4b07d2
override func viewDidLoad() {
super.viewDidLoad()
let search = MKLocalSearch(request: request)
search.startWithCompletionHandler { response, error in
response?.mapItems.forEach { item in
let point = MKPointAnnotation()
point.coordinate = item.placemark.coordinate
point.title = item.placemark.title
self.mapView.addAnnotation(point)
}
self.mapView.showAnnotations(self.mapView.annotations, animated: true)
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let mapViewController = storyboard.instantiateViewControllerWithIdentifier("MapViewController") as? MapViewController else { return }
mapViewController.request = MKLocalSearchRequest(completion: completer.results[indexPath.row])
self.showViewController(mapViewController, sender: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment