Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以更改iOS版Google Places API的结果语言吗?_Ios_Locale_Google Places Api - Fatal编程技术网

我可以更改iOS版Google Places API的结果语言吗?

我可以更改iOS版Google Places API的结果语言吗?,ios,locale,google-places-api,Ios,Locale,Google Places Api,我正在使用Google Places Api for iOS(GMSAutocompleteFilter)搜索附近的地方 如果我将英语(美国)设置为我的系统语言,它将返回繁体中文结果(这是可以接受的,因为我在台湾) 但如果我将繁体中文设置为系统语言,api将返回简体中文结果(背后的逻辑是什么?) 如何更改api搜索结果的语言 - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { GMSA

我正在使用Google Places Api for iOS(GMSAutocompleteFilter)搜索附近的地方

如果我将英语(美国)设置为我的系统语言,它将返回繁体中文结果(这是可以接受的,因为我在台湾)

但如果我将繁体中文设置为系统语言,api将返回简体中文结果(背后的逻辑是什么?)

如何更改api搜索结果的语言

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
// filter.type = kGMSPlacesAutocompleteTypeFilterCity;

[placesClient autocompleteQuery:searchText
                         bounds:nil
                         filter:filter
                       callback:^(NSArray *results, NSError *error) {
                           if (error != nil) {
                               NSLog(@"Autocomplete error %@", [error localizedDescription]);
                               return;
                           }

                           self.placeResults = results;
                           [self.resultsList reloadData];

                           for (GMSAutocompletePrediction* result in results) {
                               NSLog(@"Result '%@' with placeID %@", result.attributedFullText.string, result.placeID);
                           }
                       }];

我是iOS的PlacesAPI的工程师。谢谢你的帖子!这显然是不正确的行为,我们应该始终使用系统语言来自动完成结果


你介意在网上提出请求吗?这将帮助我们针对其他问题确定优先级,并帮助您跟踪错误的状态。

您始终可以通过编程方式更改语言设置。 斯威夫特4


我已经找到了解决这个问题的方法

由于GooglePlaceIOSSDK不允许我们指定使用的语言(这确实很奇怪),因此我们必须使用GooglePlaceAPI(基于Web)查找Place

  • 为Google Place API安装swift包装器API

  • 当您使用其
    placeID
    获取位置时,使用它以您想要的语言进行查找

  • 以下是我的
    GMSAutocompleteResultsViewControllerDelegate

    func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
                           didAutocompleteWith place: GMSPlace) {
    
    
        Log.debug("Place name: \(String(describing: place.name))")
        Log.debug("Place address: \(String(describing: place.formattedAddress))")
        Log.debug("Place attributions: \(String(describing: place.attributions))")
    
        guard let placeID = place.placeID else {
            return
        }
    
        /// Use Google Place API to lookup place information in English
        /// https://developers.google.com/places/web-service/intro
        GooglePlacesAPI.GooglePlaces.placeDetails(forPlaceID: placeID, language: "en") { (response, error) -> Void in
    
            guard let place = response?.result, response?.status == GooglePlaces.StatusCode.ok else {
                Log.debug("Error = \(String(describing: response?.errorMessage))")
                return
            }
    
            let postalCode = place.addressComponents.filter({ (components) -> Bool in
                return components.types.contains(kGMSPlaceTypePostalCode)
            }).first?.longName
    
            /// Save Selection
            let location = Location(name: place.name ?? MessageSource.getString("landmark.unknown_loc"), addr: place.formattedAddress, postal: postalCode)
    
            self.currentLocation = location
    
            self.searchController?.isActive = false
    
            ///Set text in search bar
            self.searchController?.searchBar.text = place.name
    
        }
    }
    

    你能发布代码吗?遗憾的是,似乎不可能在Google Places中为iOS更改语言…:-(完成,提前感谢。嗨@JamieMcCloskey你知道如何通过代码设置lenguaje参数,以便谷歌api(GMSAUTOMPLETIFILTER)总是以英语返回结果吗?我真的需要这个,我感谢你的帮助。
    func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
                           didAutocompleteWith place: GMSPlace) {
    
    
        Log.debug("Place name: \(String(describing: place.name))")
        Log.debug("Place address: \(String(describing: place.formattedAddress))")
        Log.debug("Place attributions: \(String(describing: place.attributions))")
    
        guard let placeID = place.placeID else {
            return
        }
    
        /// Use Google Place API to lookup place information in English
        /// https://developers.google.com/places/web-service/intro
        GooglePlacesAPI.GooglePlaces.placeDetails(forPlaceID: placeID, language: "en") { (response, error) -> Void in
    
            guard let place = response?.result, response?.status == GooglePlaces.StatusCode.ok else {
                Log.debug("Error = \(String(describing: response?.errorMessage))")
                return
            }
    
            let postalCode = place.addressComponents.filter({ (components) -> Bool in
                return components.types.contains(kGMSPlaceTypePostalCode)
            }).first?.longName
    
            /// Save Selection
            let location = Location(name: place.name ?? MessageSource.getString("landmark.unknown_loc"), addr: place.formattedAddress, postal: postalCode)
    
            self.currentLocation = location
    
            self.searchController?.isActive = false
    
            ///Set text in search bar
            self.searchController?.searchBar.text = place.name
    
        }
    }