Get your own website
Demo.swift
ContentView.swift
App.swift
 
import SwiftUI
import MapKit

struct MarkersMap: View {
  @State private var position: MapCameraPosition = .region(
    MKCoordinateRegion(
      center: CLLocationCoordinate2D(latitude: 37.3349, longitude: -122.0090),
      span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
    )
  )
  let places = [
    ("Park", CLLocationCoordinate2D(latitude: 37.3349, longitude: -122.0090)),
    ("Cafe", CLLocationCoordinate2D(latitude: 37.3327, longitude: -122.0053))
  ]
  var body: some View {
    Map(position: $position) {
      ForEach(places, id: \.0) { name, coord in
        Marker(name, coordinate: coord)
      }
    }
  }
}

                    
import SwiftUI

struct ContentView: View {
  var body: some View { MarkersMap() }
}

                    
import SwiftUI

@main
struct MyApp: App {
  var body: some Scene {
    WindowGroup { ContentView() }
  }
}