-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeantownButttons.swift
78 lines (66 loc) · 2.19 KB
/
BeantownButttons.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// BeantownButttons.swift
// Ravens
//
// Created by Eric de Quartel on 26/01/2024.
//
import MapKit
import SwiftUI
struct BeanTownButtons: View {
@Binding var position: MapCameraPosition?
@Binding var searchResults: [MKMapItem]
//
// var visibleRegion: MKCoordinateRegion?
var body: some View {
HStack {
Button {
search(for: "playground")
} label: {
Label ("Playgrounds", systemImage: "figure.and.child.holdinghands")
}
.buttonStyle(.borderedProminent)
Button {
search(for: "beach")
} label: {
Label ("Beaches", systemImage: "beach.umbrella")
}
.buttonStyle(.borderedProminent)
Button {
search(for: "museum")
} label: {
Label ("hotels", systemImage: "circle")
}
.buttonStyle(.borderedProminent)
Button {
position = .region(.boston)
} label: {
Label("Boston", systemImage: "building.2")
}
.buttonStyle(.bordered)
Button {
position = .region(.northShore)
} label: {
Label("North Shore", systemImage: "water.waves")
}
.buttonStyle (.bordered)
}
.labelStyle (.iconOnly)
}
func search(for query: String) {
let request = MKLocalSearch.Request ()
request.naturalLanguageQuery = query
request.resultTypes = .pointOfInterest
request.region = MKCoordinateRegion (
center: .parking,
span: MKCoordinateSpan (latitudeDelta: 0.0125, longitudeDelta: 0.0125))
Task {
let search = MKLocalSearch (request: request)
let response = try? await search.start ()
searchResults = response?.mapItems ?? []
}
}
}
#Preview {
// BeanTownButtons(position: .constant(.automatic), searchResults: .constant([]), visibleRegion: .boston)
BeanTownButtons(position: .constant(.automatic), searchResults: .constant([]))
}