我正在使用 Google Places AutoComplete 服务,我需要在其中过滤特定国家/地区的地点并找到 this .
直到我传递一个参数 components=country:se 来过滤自动完成字段时,它一直工作良好,它的响应是 REQUEST_DENIED
NSMutableString *url = [NSMutableString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%@&components=country:se&sensor=%@&key=%@",
[input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
SPBooleanStringForBool(sensor), key];
我需要自动完成功能来提供针对特定国家/地区的建议。
谢谢
最佳答案
这对我来说很好用。 您可以通过添加地理区域的左上角和右下角的极端位置点来添加该区域的边界。
就像我用的美国。
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:CLLocationCoordinate2DMake(52.00, 148.00)
coordinate:CLLocationCoordinate2DMake(18.00, -71.00)];
GMSPlacesClient * placesClient = [[GMSPlacesClient alloc] init];
[placesClient autocompleteQuery:fieldValue bounds:bounds filter:nil
callback:^(NSArray *results, NSError *error)
{
if (error != nil)
{
NSLog(@"Autocomplete error %@", [error localizedDescription]);
return;
}
else
{
[self.autoComplete removeAllObjects];
[self.AddressPlaceID removeAllObjects];
for (GMSAutocompletePrediction* result in results)
{
CustomAddress * parseAddress = [[CustomAddress alloc] init];
NSString * adString = [parseAddress removeCountryFromAddress:result.attributedFullText.string];
[self.autoComplete addObject:adString];
[self.AddressPlaceID addObject:result.placeID];
}
[self.autoCompleteTable reloadData];
}
}];
但您仍然可以获得其他位置结果。它会优先选择您在 GMCoordinateBounds 中定义的地理边界
关于ios - 谷歌搜索在 iOS 中放置特定于国家/地区的自动完成功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20395283/