Skip to content

Instantly share code, notes, and snippets.

@jameszaghini
Last active December 15, 2019 08:49
Show Gist options
  • Save jameszaghini/a8dd4aa290bb0d5c6be35d59121d03b7 to your computer and use it in GitHub Desktop.
Save jameszaghini/a8dd4aa290bb0d5c6be35d59121d03b7 to your computer and use it in GitHub Desktop.
Complete addresses with Swift 4, MapKit & MKLocalSearchCompleter
import MapKit
class LocationController: NSObject, MKLocalSearchCompleterDelegate {
func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
print(completer.results, "\n--------------------------\n")
}
}
var locationController = LocationController()
var completer = MKLocalSearchCompleter()
completer.delegate = locationController
var searchResults = [MKLocalSearchCompletion]()
completer.queryFragment = "1 Hu"
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
completer.queryFragment = "1 Hump"
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
completer.queryFragment = "1 Humpybong Esplanade"
}
[<MKLocalSearchCompletion 0x600002583000> 1 Hughes Street (Potts Point, NSW, Australia), <MKLocalSearchCompletion 0x600002582dc0> 1 Hunter Street (Sydney, NSW, Australia), <MKLocalSearchCompletion 0x600002582d80> 1 Hunter Street (Waterloo, NSW, Australia), <MKLocalSearchCompletion 0x600002582e40> 1 Hutchinson Walk (Zetland, NSW, Australia), <MKLocalSearchCompletion 0x600002582f80> 1 Hugo Street (Redfern, NSW, Australia), <MKLocalSearchCompletion 0x600002583080> 1 Hunter Street (Woolwich, NSW, Australia), <MKLocalSearchCompletion 0x600002582f40> 1 Hunter Crescent (North Sydney, NSW, Australia), <MKLocalSearchCompletion 0x600002582e80> 1 Hume Street (Wollstonecraft, NSW, Australia), <MKLocalSearchCompletion 0x6000025830c0> 1 Hubert Street (Leichhardt, NSW, Australia), <MKLocalSearchCompletion 0x600002583100> 1 Hunter Street (Lewisham, NSW, Australia), <MKLocalSearchCompletion 0x6000025831c0> 1 Hughes Avenue (Mascot, NSW, Australia), <MKLocalSearchCompletion 0x600002583240> 1 Huntleys Point Road (Huntleys Point, NSW, Australia), <MKLocalSearchCompletion 0x600002583140> 1 Hume Highway (Greenacre, NSW, Australia), <MKLocalSearchCompletion 0x600002582fc0> 1 Humphrey Street (Rosebery, NSW, Australia), <MKLocalSearchCompletion 0x600002582ec0> 1 Hunter Street (Dover Heights, NSW, Australia)]
--------------------------
[<MKLocalSearchCompletion 0x6000025ba840> 1 Humphrey Street (Rosebery, NSW, Australia), <MKLocalSearchCompletion 0x6000025bb240> 1 Humphreys Lane (Hurstville, NSW, Australia), <MKLocalSearchCompletion 0x6000025bb340> 1 Humphrey Street (Lidcombe, NSW, Australia), <MKLocalSearchCompletion 0x6000025bb380> 1 Humphries Road (Wakeley, NSW, Australia), <MKLocalSearchCompletion 0x6000025bb440> 1 Humphreys Road (Kincumber South, NSW, Australia)]
--------------------------
[<MKLocalSearchCompletion 0x600002594080> 1 Humpybong Esplanade (Redcliffe, QLD, Australia)]
--------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment