|
|
import SwiftUI
|
|
|
|
|
|
// MARK: - 地理位置输入组件
|
|
|
struct LocationInputView: View {
|
|
|
@Binding var latitude: String
|
|
|
@Binding var longitude: String
|
|
|
@Binding var locationName: String
|
|
|
@FocusState var focusedField: LocationField?
|
|
|
|
|
|
// 地理位置字段枚举
|
|
|
enum LocationField: Hashable {
|
|
|
case latitude, longitude, locationName
|
|
|
}
|
|
|
|
|
|
var body: some View {
|
|
|
VStack(spacing: 16) {
|
|
|
// 位置名称
|
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
|
HStack {
|
|
|
Text("位置名称")
|
|
|
.font(.subheadline)
|
|
|
.foregroundColor(.primary)
|
|
|
Spacer()
|
|
|
}
|
|
|
|
|
|
TextField("例如:纽约时代广场", text: $locationName)
|
|
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
|
.focused($focusedField, equals: .locationName)
|
|
|
}
|
|
|
|
|
|
// 坐标输入
|
|
|
HStack(spacing: 12) {
|
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
|
HStack {
|
|
|
Text("纬度")
|
|
|
.font(.subheadline)
|
|
|
.foregroundColor(.primary)
|
|
|
Text("*")
|
|
|
.foregroundColor(.red)
|
|
|
Spacer()
|
|
|
}
|
|
|
|
|
|
TextField("40.7589", text: $latitude)
|
|
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
|
.keyboardType(.decimalPad)
|
|
|
.focused($focusedField, equals: .latitude)
|
|
|
}
|
|
|
|
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
|
HStack {
|
|
|
Text("经度")
|
|
|
.font(.subheadline)
|
|
|
.foregroundColor(.primary)
|
|
|
Text("*")
|
|
|
.foregroundColor(.red)
|
|
|
Spacer()
|
|
|
}
|
|
|
|
|
|
TextField("-73.9851", text: $longitude)
|
|
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
|
.keyboardType(.decimalPad)
|
|
|
.focused($focusedField, equals: .longitude)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 坐标格式说明
|
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
|
HStack {
|
|
|
Image(systemName: "info.circle")
|
|
|
.font(.caption)
|
|
|
.foregroundColor(.blue)
|
|
|
|
|
|
Text("坐标格式说明")
|
|
|
.font(.caption)
|
|
|
.foregroundColor(.primary)
|
|
|
|
|
|
Spacer()
|
|
|
}
|
|
|
|
|
|
Text("• 纬度范围:-90 到 90\n• 经度范围:-180 到 180\n• 使用小数点分隔,如:40.7589")
|
|
|
.font(.caption)
|
|
|
.foregroundColor(.secondary)
|
|
|
.lineLimit(nil)
|
|
|
}
|
|
|
.padding(.horizontal, 12)
|
|
|
.padding(.vertical, 8)
|
|
|
.background(
|
|
|
RoundedRectangle(cornerRadius: 8)
|
|
|
.fill(Color.blue.opacity(0.1))
|
|
|
)
|
|
|
}
|
|
|
.toolbar {
|
|
|
ToolbarItemGroup(placement: .keyboard) {
|
|
|
Spacer()
|
|
|
Button("完成") {
|
|
|
focusedField = nil
|
|
|
}
|
|
|
.foregroundColor(.blue)
|
|
|
.font(.system(size: 16, weight: .medium))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#Preview {
|
|
|
LocationInputView(
|
|
|
latitude: .constant(""),
|
|
|
longitude: .constant(""),
|
|
|
locationName: .constant("")
|
|
|
)
|
|
|
} |