[Swift UI] Use Map view

What is this article?

In iOS13, working with MapKit in SwiftUI required wrapping in a UIKit compatible view. It seems that Map was implemented as a native view of SwiftUI in iOS14. Here, I put the code of "View to display the location of Apple headquarters on the map".



Map view of Swift UI

import SwiftUI
import MapKit

struct MapView: View {
    @State var region = MKCoordinateRegion(
        center: CLLocationCoordinate2D(latitude: 37.3351, longitude: -122.0088),
        span: MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02))
    var body: some View {
        Map(coordinateRegion: $region)

struct MapView_Previews: PreviewProvider {
    static var previews: some View {


スクリーンショット 2021-01-16 13.02.48.png

Recommended Posts

[Swift UI] Use Map view
Swift UI 100 knocks
Customize View with View Modifier in Swift UI
(For beginners) Swift UI view element collection
Shiritori map app made with Swift UI
Incorporate View created with Swift UI into ViewController
Swift UI TextView placeholder
How to use map
Starting with Swift Swift UI
How to use Map
[Java] How to use Map
[Java] How to use Map
[Swift] After installing Scroll View
[Swift] Let's use Segmented Control
Use Swift Package on Playground
[Swift] Try using Collection View
[Swift] How to use UserDefaults
How to use Swift UIScrollView
Let's use Swift Firebase Firebase Auth
How to use Java Map
[Swift] Templates and explanations of basic functions using Map Kit View
[Swift] Another way to use Result?
Create Master Detail in Swift UI
Use composite keys in Java Map.
[Swift] How to use SwiftLint (cocoapods)
[Swift] How to use Unwind segue
[Swift 5] Implement UI for review function
Install Xcode and use Hello Swift!