Embedding a UIKit MapView in SwiftUI
One of the reasons for the success of smartphones is the possibility of showing the current position on a map in real time, preventing users from getting lost in an unknown part of a city.
Since the its release, the iPhone has provided a fantastic map experience thanks to MapKit, the framework implemented by Apple that, from iOS 6, replaces the Google Maps SDK.
In the preceding recipe, Embedding a MapView in SwiftUI, we saw how simple it is to show a Map
SwiftUI component.
However, the SwiftUI native Map
component is available from iOS 14 only. Since not all iOS apps can be updated to support only the latest version of iOS, because most customers are still on iOS 13, in this recipe, we'll see how to wrap the UIKit MKMapView
component in UIViewRepresentable
and use it in a SwiftUI app.
We'll implement the same app as we did in Embedding a MapView in SwiftUI, where we create a list of favorite places.
Getting ready
Let...