1

how to get location details in arabic language I tried this code , but I always get it in English .

func fetchCountryAndCity(location: CLLocation, completion: @escaping (String, String, String) -> ())
{

    //let gg : GMSGeocoder = GMSGeocoder()


    let geo : CLGeocoder = CLGeocoder()
    geo.accessibilityLanguage = "ar"


    geo.reverseGeocodeLocation(location) { placemarks, error in
        if let error = error {
            print(error)
        } else if let country = placemarks?.first?.country,
            let city = placemarks?.first?.locality , let SubAdminArea = placemarks?.first?.subLocality {
            completion(country, city , SubAdminArea)
        }
    }
}
  • 1
    Possible duplicate of [Reverse geocoding to return results only in English?](https://stackoverflow.com/questions/25144508/reverse-geocoding-to-return-results-only-in-english) – Frankie Apr 11 '18 at 23:47

1 Answers1

1

Starting in iOS 11, you can pass a locale to the reverseGeocodeLocation request. This will return all results in Saudi Arabian Arabic:

let locale = Locale(identifier: "ar_sa")

CLGeocoder().reverseGeocodeLocation(location, preferredLocale: locale) { placemarks, error in
    // ...
}

For iOS < 11, you have to temporarily changes your app's preferred language to Arabic:

// Switch your app's preferred language to Arabic
UserDefaults.standard.set(["ar"], forKey: "AppleLanguages")

CLGeocoder().reverseGeocodeLocation(location) { placemarks, error in
    // Remove the language override
    UserDefaults.standard.removeObject(forKey: "AppleLanguages")

    // ...
}

(Pardon my ignorance as I do not know how to read Arabic so I don't know if the result is correct)

Code Different
  • 90,614
  • 16
  • 144
  • 163