How to use Map in SwiftUI

Apple has finally given us a simple way to display maps in our apps

Kelvin Tan
Swiftly Engineered iOS

--

Photo by Tabea Damm on Unsplash.

Apple has revamped the experience for Map on iOS, providing more control over location privacy. With that in mind, I was actually surprised to learn that Apple introduced Map. I was pretty sure they had already released it, but upon checking, it was actually MapView.

I compared Map and MapView and found out that MapView is actually for UIKit, while Map is for SwiftUI.

Bear in mind that if you use Map, your operating system that will be supported is iOS 14+. It is iOS 3+ for MapView.

“A view that displays an embedded map interface.” — Apple Developer

Prerequisites

To follow along with this tutorial, you’ll need some basic knowledge in:

  • Swift
  • At least Xcode 12+

Map

Let’s dive in and see what Map is capable of. You can select a location to be presented, and I am using the Petronas Twin Towers in Malaysia — the tallest twin towers in the world.

You may begin creating MKCoordinateRegion by indicating the latitude and longitude of a location. MKCoordinateSpan is being used as the zoom…

--

--

Kelvin Tan
Swiftly Engineered iOS

Father, husband, software engineer. Building software and building a family, one line of code and one moment at a time. 🚀💻💙 http://ko-fi.com/kelvintanzy