-
Notifications
You must be signed in to change notification settings - Fork 0
mapkit
tyler edited this page Oct 10, 2023
·
1 revision
- μ΅λν
SwiftUIλ₯Ό νμ©νκ³ μ νμΌλ μ’μ κΈ°λ₯(?) λ€μiOS 17.0λ²μ μ΄μλΆν° κ°λ₯ν κ²λ€μ΄ λ§μκ³ ,iOS 17.0λ²μ μλμSwiftUIμμμMapKitꡬνμ μ μ½μ΄ λ§μμ΅λλ€. κ·Έλ¬νμ¬UIKitμ μ¬μ©νλ μ΅λνSwiftUIμ νΈνλλλ‘UIViewRepresentableλ₯Ό μ¬μ©νμ¬Mapμ ꡬννμμ΅λλ€.
-
iOS 17.0λ²μ μΌλ‘ λμ λ²μ μμλ§ νΈνμ΄ κ°λ₯νμ¬ μΆν μμ ν λμμ λ μ μ©νλ κ²μ΄ μ’μ λ― ν©λλ€.
-
position: MapCameraPositionλ‘ μ§λ νλ©΄ μ‘°μ κ°λ₯ -
Map(position: $position) {μ²λΌ μ€κ΄νΈλ₯Ό μ΄μ΄ Map μ λ£μ μμλ€μ SwiftUI λ§μΌλ‘ κ΄λ¦¬ κ°λ₯'
struct MapView_iOS17: View {
@State private var position: MapCameraPosition = .camera(.init(centerCoordinate: .duckRun, distance: 1800.0, heading: -80.0))
var body: some View {
Map(position: $position) {
UserAnnotation()
Annotation("μ€λ¦¬λ°", coordinate: .duckRun) {
ZStack {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.foregroundStyle(.yellow)
Image("duck")
.resizable()
.scaledToFit()
.frame(width: 30)
.padding(5)
}
}
}
...-
iOS 17.0μ΄μ λ²μ μμ μ§μλλMapKitμ μ μ½μ΄ λ무 λ§μ΅λλ€.- Map Rotation μ μ§μνμ§ μμ΅λλ€. μ¬μ©μκ° μμ λ‘κ² λ§΅μ μ‘°μν μ μμ΅λλ€.
-
userTrackingModeμMKPolylineμͺ½μμ μ νμ΄ λ§μ΅λλ€.
- 볡μ‘ν λ³μ κ΄λ¦¬
- UIKit μμ€μΌλ‘ κ΄λ¦¬ν΄μΌ ν λ³μκ° λ무 λ§κ³ μ΄λ¦μ΄ κΉλλ€.
- λ¬Όλ‘ μ‘°κΈλ digging ν΄λ³΄λ©΄ λ°©λ²μ΄ μκ² μ§λ§ κ²°κ΅ UIKit μ νΌμ©ν΄μ μ¬μ©ν΄μΌ ν κ²μ΄λΌλ κ²°λ‘ μ λ€λ€λμ΅λλ€.
// 17.0 μμλ MapCameraPosition μ ν΄λΉνλ λΆλΆ
@State private var camera = MKMapCamera(lookingAtCenter: .duckRun, fromDistance: 1800, pitch: 0, heading: -80)
// Annotation μ μν λ³μ
let duckRunPoints = [
RunPoint(title: "μ€λ¦¬λ°", coordinate: .duckRun, image: "duck"),
RunPoint(title: "μ€ννΈ ν¬μΈνΈ", coordinate: CLLocationCoordinate2D(latitude: 37.53958, longitude: 127.07435), image: "startpoint")
]
var body: some View {
VStack(spacing: 30) {
Map(coordinateRegion: $region,
interactionModes: interactionMode,
showsUserLocation: true,
userTrackingMode: $userTracking,
annotationItems: duckRunPoints,
annotationContent: { location in
MapAnnotation(coordinate: location.coordinate) {
if location.title == "μ€λ¦¬λ°" {
VStack {
Image(location.image)
.resizable()
.scaledToFit()
.frame(width: 30)
Text(location.title)
.font(.caption2)
.foregroundStyle(.secondary)
}
} else {
VStack {
Image(location.image)
.resizable()
.scaledToFit()
.frame(width: 15)
Text(location.title)
.font(.system(size: 6))
.foregroundStyle(.secondary)
}
}
}
})
...