I am implementing an auto-complete feature for users to search for address based on their input.
However, I want to ensure that the search results are always in English, regardless of the user's phone language.
While I considered using completer.region of English-speaking countries, this would restrict the feature's usability and provide me results only from the region I specified.
private lazy var localSearchCompleter: MKLocalSearchCompleter = {
let completer = MKLocalSearchCompleter()
completer.delegate = self
completer.resultTypes = .address
return completer
}()
func searchAddress(_ searchableText: String) {
guard searchableText.isEmpty == false else { return }
localSearchCompleter.queryFragment = searchableText
}
Does someone have an Idea how can I solve this issue?)
I was trying using completer.region but it limited the results to this region only.
After spending a significant amount of time trying to resolve the issue, I was able to find a solution! Instead of trying to obtain the completer in English, I utilized some features provided by Apple.
First, I used the lookUpCurrentLocation function to retrieve the suggested location with the additional parameters of street, city, and country.
Inside this function, I utilized the getCoordinate function to retrieve the CLLocationCoordinate2D object and built a CLLocation based on the latitude and longitude.
To obtain the placemark in English, I then used CLGeocoder().reverseGeocodeLocation with the coordinates and preferredLocale parameter set to the desired language. This provided me with an accurate English (or any other language) placemark.
That's all! I hope this solution is helpful to others facing similar issues.