How to Improve Your SwiftUI Map

Luca Jonscher
The Startup

--

⚠️ Deprecated

With SwiftUI 2 Apple added the Map() structure to display MapKit maps in your app.

Although it isn’t as powerful as a MKMapView yet, it’s still a great way to embed simple or even more complex maps in your app. With the Map() structure you can create maps, that display the user’s location and add a variety of annotations. But some important things are missing. There isn’t a parameter to change the map type, to show the scale or to add an overlay. In this article I’ll show you how to still add thing like these while still using SwiftUI’s Map() .

How to change the map type

Just like you can style the .navigationBar() with UINavigationBar or a TextField() with UITextField you can style the Map() with MKMapView . To do so, you access the function .appearance() and get a big selection of variables and functions. To change the map type you use MKMapView.appearance().mapType = MKMapType . Instead of MKMapType put in the style you want, e.g. .satellite . All styles are listed on the Apple Developer website.

--

--

Luca Jonscher
The Startup

Designer, Developer, Creative. Freelance graphic designer. From Germany. Thrice Apple Swift Student Challenge winner.