view
var body: some View {
HStack {
Button {
search(for: "playground")
} label: {
Label("Playgrounds", systemImage: "figure.and.child.holdinghands")
}
.buttonStyle(.borderedProminet)
Button {
search(for: "playground")
} label: {
Label("Playgrounds", systemImage: "figure.and.child.holdinghands")
}
.buttonStyle(.borderedProminet)
}
.labelStyle(.iconOnly)
}
search
@Binding var searchResults: [MKMapItem]
func search(for query: String, region: MKCoordinateRegion? = nil) {
let request = MKLocalSearch.Request()
request.naturalLanguageQuery = query
request.resultTypes = .pointOfInterest
if let region = region {
request.region = region
}
Task {
let search = MKLocalSearch(request: request)
let response = try? await search.start()
searchResults = response?.mapItems ?? []
}
}