iOS Mapkit

Jehyeon Lee·2024년 4월 12일
0
post-thumbnail

오늘은 간단히 iOS에 MapKit프레임워크를 사용해보도록 하겠습니다.

Map()을 사용하기 위해서는

Map(coordinateRegion: , annotationItems: , annotationContent: 

region, item, content가 필요합니다.
region은 맵이 켜질때 어느 위치에 있을지 정하는것입니다.
item은 맵에 특정부분을 가르키는 마커들의 집합입니다.
Content는 핀들의 뷰를 클로저로 받아 뷰로 뱉습니다. (사용자정의하는곳)

map에 기본적인 PIN 방식으로 사용하기


 MapPin(coordinate: item.location, tint: .accent)
           

MapMarker를 사용하기


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)
            }
            
        }

참고

https://www.udemy.com/course/swiftui-masterclass-course-ios-development-with-swift/learn/lecture/22673459#overview

profile
공부한거 느낌대로 써내려갑니당

0개의 댓글

관련 채용 정보