我正在使用以下方法获取GMSPlacesClient类的输入字符串的自动完成结果:
- (void)autocompleteQuery:(NSString *)query
bounds:(GMSCoordinateBounds * GMS_NULLABLE_PTR)bounds
filter:(GMSAutocompleteFilter * GMS_NULLABLE_PTR)filter
callback:(GMSAutocompletePredictionsCallback)callback
我尝试通过多种方式实现边界,但没有一种方法有效,我想知道是否有任何标准方法可以通过GMSCoordinateBounds获取特定国家/地区的结果?
答案 0 :(得分:27)
您可以使用Google自动填充位置api iOS SDK获取具体国家/地区的结果。请转到此link
let filter = GMSAutocompleteFilter()
filter.type = .Establishment
filter.country = "UK"
将过滤器国家/地区设置为您想要的国家/地区代码。然后,这将为您提取仅针对特定国家/地区的结果。
您可以从此link
获取国家/地区代码希望这会有所帮助。
答案 1 :(得分:4)
这个对我有用
function func(a, b, c) {
var cmp = a ? gt : lt;
if (cmp(b, c)) {
return 'Hi';
}
return 'Bye';
}
function lt(a, b) {
return a < b;
}
function gt(a, b) {
return a > b;
}
答案 2 :(得分:3)
In your google places API url, just append
&components=country:sg
here sg = country code for singapore. Append country code as per your requirement.
The country must be passed as a two character, ISO 3166-1 Alpha-2 compatible country code. you can refer Country code Of different countries
答案 3 :(得分:0)
Looks like Google autocomplete Places API for iOS doesn't support filtering by country. GMSCoordinateBounds
uses the northEast and southWest bounds corresponding to the rectangular region defined by the two corners.
It might be easier to use Google Places API Web Service and filter with components=country:
You can specify what country you want after country:
答案 4 :(得分:0)
国家代码的完整列表可以在这里找到:
https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
用于:
let filter = GMSAutocompleteFilter()
filter.country = "YOURCountryCode"