如何获得国家特定的结果与谷歌自动完成的地方api ios sdk?
我使用下面的方法来获取GMSPlacesClient类的inputstring的自动完成结果:
- (void)autocompleteQuery:(NSString *)query bounds:(GMSCoordinateBounds * GMS_NULLABLE_PTR)bounds filter:(GMSAutocompleteFilter * GMS_NULLABLE_PTR)filter callback:(GMSAutocompletePredictionsCallback)callback
我试图通过多种方式来实现边界,但没有一个工作,我不知道是否有任何标准的方法来获得与GMSCoordinateBounds国家特定的结果?
您可以使用Google自动填充位置iOS SDK获取特定国家/地区的结果。 只要去这个链接
let filter = GMSAutocompleteFilter() filter.type = .Establishment filter.country = "UK"
将filter国家设置为所需的国家/地区代码。 这将只为您提取国家特定的结果。
您可以从此链接获取国家/地区代码
希望这可以帮助。
在你的谷歌API的url,只是追加
&components=country:sg here sg = country code for singapore. Append country code as per your requirement.
该国必须通过符合ISO 3166-1 Alpha-2的两个字符的国家代码。 你可以参考不同国家的国家代码
这一个为我工作
let placesClient = GMSPlacesClient() let filter = GMSAutocompleteFilter() filter.type = .Establishment filter.country = "SG" placesClient.autocompleteQuery(searchString, bounds: nil, filter: filter) { (results, error:NSError?) -> Void in self.resultsArray.removeAll() if let _ = results { for result in results!{ if let res: GMSAutocompletePrediction = result { // your code } } } }
看起来像谷歌自动完成Places API的iOS不支持按国家过滤。 GMSCoordinateBounds
使用与两个angular定义的矩形区域对应的东北和西南边界。
使用Google Places API Web服务并使用components=country:
过滤可能会更容易components=country:
您可以指定国家之后您想要的country: