오늘은 간단히 iOS에 MapKit프레임워크를 사용해보도록 하겠습니다.
Map()을 사용하기 위해서는
Map(coordinateRegion: , annotationItems: , annotationContent:
region, item, content가 필요합니다.
region은 맵이 켜질때 어느 위치에 있을지 정하는것입니다.
item은 맵에 특정부분을 가르키는 마커들의 집합입니다.
Content는 핀들의 뷰를 클로저로 받아 뷰로 뱉습니다. (사용자정의하는곳)
MapPin(coordinate: item.location, tint: .accent)
MapMarker(coordinate: item.location, tint: .accentColor)
MapAnnotation(coordinate: item.location) {
Image("logo")
.resizable()
.scaledToFit()
.frame(width: 32,height: 32, alignment: .center)
}
예시 코드
Map(coordinateRegion: $region, annotationItems: locations) { item in
// MapPin(coordinate: item.location, tint: .accent)
// MapMarker(coordinate: item.location, tint: .accentColor)
MapAnnotation(coordinate: item.location) {
Image("logo")
.resizable()
.scaledToFit()
.frame(width: 32,height: 32, alignment: .center)
}
}
참고