Implementing address autocomplete using SwiftUI and MapKit

Surprisingly for myself, I realized that I have never implemented address autocompletion using only Apple technologies. Before, I had experience only with Google Places SDK and even with the not-so-well-known European GeoDataHub. I found it curious — to know how we can limit ourselves to using only SwiftUI and MapKit to solve a similar problem.

TL;DR

GitHub - maxkalik/address-autocomplete-swiftui: SwiftUI solution of Address autocomplete

You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…

github.com

MapKit

Before starting let’s briefly describe MapKit — a powerful framework invented by Apple. See documentation:

Display map or satellite imagery within your app, call out points of interest, and determine placemark information for map coordinates.

The framework includes a bunch of useful things. I will list only what we are going to use: the Map itself (MapView for SwiftUI); MKCoordinateRegion — this model will allow showing a particular region on the map; MKAnnotation — another model with coordinates and other data for showing MapMarker on the map, and MKLocalSearch engine which we are going to use to get a list of completions from searchable address. To implement this we need to useMKLocalSearchCompleterDelegate and MKLocalSearchCompleter where we can get results — possible addresses.

Learn More

Tags: MapKit SwiftUI