Created
June 16, 2022 23:13
-
-
Save aheze/dc3d29b4893727d5a24d842c0bb799a0 to your computer and use it in GitHub Desktop.
Get multiple map locations from a query string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Shared { | |
static func getMatchingLocations(from query: String, region: MKCoordinateRegion) async -> (locations: [MKMapItem], region: MKCoordinateRegion?) { | |
let request = MKLocalSearch.Request() | |
request.naturalLanguageQuery = query | |
request.region = region | |
let search = MKLocalSearch(request: request) | |
return await withCheckedContinuation { continuation in | |
search.start { response, _ in | |
guard let response = response else { | |
continuation.resume(returning: ([], nil)) | |
return | |
} | |
let locations = response.mapItems | |
continuation.resume(returning: (locations, response.boundingRegion)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment