Implementing address autocomplete using SwiftUI and MapKit

<p>Surprisingly for myself, I realized that I have never implemented address autocompletion using only Apple technologies. Before, I had experience only with&nbsp;<a href="https://developers.google.com/maps/documentation/places/ios-sdk/autocomplete" rel="noopener ugc nofollow" target="_blank">Google Places SDK</a>&nbsp;and even with the not-so-well-known European&nbsp;<a href="http://geodatahub.eu/" rel="noopener ugc nofollow" target="_blank">GeoDataHub</a>. I found it curious &mdash; to know how we can limit ourselves to using only SwiftUI and MapKit to solve a similar problem.</p> <h1>TL;DR</h1> <h2><a href="https://github.com/maxkalik/address-autocomplete-swiftui?source=post_page-----c094d08cda24--------------------------------" rel="noopener ugc nofollow" target="_blank">GitHub - maxkalik/address-autocomplete-swiftui: SwiftUI solution of Address autocomplete</a></h2> <h3><a href="https://github.com/maxkalik/address-autocomplete-swiftui?source=post_page-----c094d08cda24--------------------------------" rel="noopener ugc nofollow" target="_blank">You can&#39;t perform that action at this time. You signed in with another tab or window. You signed out in another tab or&hellip;</a></h3> <p><a href="https://github.com/maxkalik/address-autocomplete-swiftui?source=post_page-----c094d08cda24--------------------------------" rel="noopener ugc nofollow" target="_blank">github.com</a></p> <h1>MapKit</h1> <p>Before starting let&rsquo;s briefly describe MapKit &mdash; a powerful framework invented by Apple.&nbsp;<a href="https://developer.apple.com/documentation/mapkit/" rel="noopener ugc nofollow" target="_blank">See documentation</a>:</p> <blockquote> <p>Display map or satellite imagery within your app, call out points of interest, and determine placemark information for map coordinates.</p> </blockquote> <p>The framework includes a bunch of useful things. I will list only what we are going to use: the Map itself (<code>MapView</code>&nbsp;for SwiftUI);&nbsp;<code>MKCoordinateRegion</code>&nbsp;&mdash; this model will allow showing a particular region on the map;<code>&nbsp;</code>MKAnnotation &mdash; another model with coordinates and other data for showing&nbsp;<code>MapMarker</code>&nbsp;on the map, and&nbsp;<code>MKLocalSearch</code>&nbsp;engine which we are going to use to get a list of completions from searchable address. To implement this we need to use<code>MKLocalSearchCompleterDelegate</code>&nbsp;and&nbsp;<code>MKLocalSearchCompleter</code>&nbsp;where we can get results &mdash; possible addresses.</p> <p><a href="https://levelup.gitconnected.com/implementing-address-autocomplete-using-swiftui-and-mapkit-c094d08cda24"><strong>Learn More</strong></a></p>
Tags: SwiftUI MapKit