Hello,
My app uses Core Location to request for Points Of Interest near the user. I used the different APIs provided by Apple: MKLocalPointsOfInterestRequest
, MKLocalSearch.Request
and MKLocalSearchCompleter
. They do not provide the same results at all, whereas the configurations for the requests are very similar.
The MKLocalPointsOfInterestRequest
provides very few places (if any, sometimes The operation couldn’t be completed. (MKErrorDomain error 4.)
The others give more results but not identical. The code for the different requests is provided below.
- Is this the expected behaviour?
- If no, have I missed something?
- Is this a bug?
Thanks
PS: Tested on Xcode 14.3, iOS 16.0.
MKLocalPointsOfInterestRequest
let center: CLLocationCoordinate2DMake = CLLocationCoordinate2DMake(41.38891, 9.16205)
let poiRequest: MKLocalPointsOfInterestRequest = MKLocalPointsOfInterestRequest(center: coordinate, radius: 3_000)
poiRequest.pointOfInterestFilter = MKPointOfInterestFilter(including: [.beach])
let poiSearch: MKLocalSearch = MKLocalSearch(request: poiRequest)
let resultsPOI = try await poiSearch.start()
print(resultsPOI.mapItems.compactMap(\.name))
This give me the following result:
["Plage de Stagnolu"]
MKLocalSearch.Request
let center: CLLocationCoordinate2DMake = CLLocationCoordinate2DMake(41.38891, 9.16205)
let searchRequest: MKLocalSearch.Request = MKLocalSearch.Request()
searchRequest.region = MKCoordinateRegion(center: coordinate, latitudinalMeters: 4_000, longitudinalMeters: 4_000)
searchRequest.pointOfInterestFilter = MKPointOfInterestFilter(including: [.beach])
searchRequest.resultTypes = .pointOfInterest
searchRequest.naturalLanguageQuery = "beach"
let search: MKLocalSearch = MKLocalSearch(request: searchRequest)
let results = try? await search.start()
print(results.mapItems.compactMap(\.name))
This give me se following results.
["Plage du Petit Sperone", "Plage de 3 Pointes", "Plage de Saint-Antoine Bonifacio", "Plage de Fazzio", "Piantarella Beach", "Plage du Grand Sperone", "Capu Testagro", "Plage de Balistra", "Plage de Stagnolo", "Plage de Cala Longa", "Plage de La Tonnara", "Plage Porto Novo", "Plage de Sant\'Amanza", "Rena Majori", "Plage de Rondinara", "Plage de Santa Giulia", "Spiaggia Rena Bianca", "Plage De Roccapina", "Cala Spinosa", "Naracu Nieddu Beach", "Porto Cervo Beach", "Lido Dog Beach", "Plage de Figari", "Capocchia Du Purpu", "Spiaggia Zia Culumba"]
MKLocalSearchCompleter
func search(coordinate: CLLocationCoordinate2D) {
completer.region = MKCoordinateRegion(center: coordinate, latitudinalMeters: 4_000, longitudinalMeters: 4_000)
completer.pointOfInterestFilter = MKPointOfInterestFilter(including: [.beach])
completer.resultTypes = .pointOfInterest
completer.queryFragment = "beach"
}
func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
print(completer.results.map(\.title))
}
This give me the following result:
["Porto Istana Beach", "Sandbanks Beach", "Spiaggia La Cinta", "Piantarella Beach", "Platja de la Barceloneta", "Whitstable Beach", "West Wittering Beach", "Cala Millor"]