How to force language in which reverse geocoding data on iOS is received?

前端 未结 4 789
栀梦
栀梦 2021-01-14 06:04

When i call

geocoder reverseGeocodeLocation:currentLoc completionHandler:

i get all the data (city, county, ...) in a language according t

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 06:26

    iOS 11 has a new -reverseGeocode... method that accepts a locale to use:

    - (void)reverseGeocodeLocation:(CLLocation *)location preferredLocale:(NSLocale *)locale
        completionHandler:(CLGeocodeCompletionHandler)completionHandler
    

    Swift signature:

    func reverseGeocodeLocation(_ location: CLLocation, preferredLocale locale: Locale?, completionHandler: @escaping CLGeocodeCompletionHandler)
    

    Put whatever locale you like. This example just uses the current locale

    NSLocale *currentLocale = [NSLocale currentLocale];
    [self.geocoder reverseGeocodeLocation:self.location preferredLocale:currentLocale
        completionHandler:^(NSArray * _Nullable placemarks, NSError * _Nullable error) {
    
        // Handle the result or error
    }];
    

提交回复
热议问题