Created
March 30, 2016 02:47
-
-
Save hanawat/5bee80f6dc0ed9ded4bde93d278a4b9f to your computer and use it in GitHub Desktop.
iOS9.3で追加されたMKLocalSearchCompleterを試す ref: http://qiita.com/hanawat/items/1f3f3c277a8f2c4b07d2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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