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 <a href="https://developers.google.com/maps/documentation/places/ios-sdk/autocomplete" rel="noopener ugc nofollow" target="_blank">Google Places SDK</a> and even with the not-so-well-known European <a href="http://geodatahub.eu/" rel="noopener ugc nofollow" target="_blank">GeoDataHub</a>. I found it curious — 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't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…</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’s briefly describe MapKit — a powerful framework invented by Apple. <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> for SwiftUI); <code>MKCoordinateRegion</code> — this model will allow showing a particular region on the map;<code> </code>MKAnnotation — another model with coordinates and other data for showing <code>MapMarker</code> on the map, and <code>MKLocalSearch</code> 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> and <code>MKLocalSearchCompleter</code> where we can get results — possible addresses.</p>
<p><a href="https://levelup.gitconnected.com/implementing-address-autocomplete-using-swiftui-and-mapkit-c094d08cda24"><strong>Learn More</strong></a></p>