-
SwiftUI Maps 65 - 지도에 주석(Annotations) 달기SwiftUI 100 레시피/Maps 2022. 6. 27. 18:36
import SwiftUI
import MapKit
struct Place: Identifiable{
let id = UUID()
let name: String
let coordinate: CLLocationCoordinate2D
}
struct ContentView: View {
@State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.808208, longitude: -122.415802), latitudinalMeters: 5000, longitudinalMeters: 5000)
let annotations = [
Place(name: "A지역", coordinate: CLLocationCoordinate2D(latitude: 37.807920, longitude: -122.422949)),
Place(name: "B지역", coordinate: CLLocationCoordinate2D(latitude: 37.804895, longitude: -122.429654)),
Place(name: "C지역", coordinate: CLLocationCoordinate2D(latitude: 37.807319, longitude: -122.421907)),
]
var body: some View {
//Map(coordinateRegion: $region)
Map(coordinateRegion: $region, annotationItems: annotations){
MapPin(coordinate: $0.coordinate)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
'SwiftUI 100 레시피 > Maps' 카테고리의 다른 글
SwiftUI Maps 68 - 맵 타입 변경하기(일반,위성,하이브리드) (0) 2022.06.28 SwiftUI Maps 67 - 사용자 위치 표시하기 (0) 2022.06.28 SwiftUI Maps 66 - 커스텀 주석(Annotations) 만들기 (0) 2022.06.28 SwiftUI Maps 64 - 지도 표시하기 (0) 2022.06.27