【发布时间】:2021-05-29 07:42:40
【问题描述】:
所以我目前有这段代码,它显示了一个带有大头针的地图。
但我想知道如何显示多个图钉而不仅仅是一个图钉并显示用户当前位置,所以如果用户移动“点”也应该移动
如果用户点击图钉,我想在控制台打印一些东西
struct GeoPointView : View {
var position : GeoPoint
struct IdentifiablePoint: Identifiable {
var id = UUID()
var position : GeoPoint
}
var body: some View {
Map(coordinateRegion: .constant(
MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: position.latitude, longitude: position.longitude), span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))), annotationItems: [position].map { IdentifiablePoint(position: $0)}) { point in
MapPin(coordinate: CLLocationCoordinate2D(latitude: point.position.latitude, longitude: point.position.longitude))
}
.cornerRadius(10)
}
}
【问题讨论】:
标签: ios dictionary swiftui geolocation location