From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

SwiftUI maps

SwiftUI maps

- [Instructor] You've taken my course, SwiftUI Essential Training. I cover there how to add a map using UIViewRepresentable. In iOS 14, SwiftUI lets you add a map and annotations directly to a view with a map view. Let's take a look at how you do this. If you look at the exercise files and you go all the way to the top here, you will see that I actually imported MapKit, which you have to do in order to get this to work right. After that, I gave you some code for a coordinate in a region, and we'll talk about this other thing in a minute, but we're going to go down here to the content view, and getting a map in here is relatively easy. All you really need to do is put in map. And if we do an escape here, you'll see that it has a coordinate region. Now, you'll notice the coordinate region is a binding variable. So I'm going to go up here... And add a state variable to handle this. And that's going to be mapRegion equals…

Contents