ios - 谷歌搜索在 iOS 中放置特定于国家/地区的自动完成功能

标签 ios

我正在使用 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/

相关文章:

ios - 在 Swift 中解析 CSV 文件并将其加载到 Core Data 中

Swift 中的 iOS 水平可滚动标签栏

ios - Objective C iPhone 编程一个点或形状来跟随你的光标

javascript - iOS websql 限制

ios - 使用 Delegate 插入行时出现 NSInternalInconsistencyException 错误

c# - Xamarin.forms - 如何在 MapView 上创建可拖动元素(标记)?

ios - 如何向 AVPlayerViewController 添加自定义按钮?

ios - parse.com 需要来自其他表的图像

ios - iOS 上的 flutter : How to trigger pop-up for allowing local network access

ios - 如何在代码中创建自定义 UIButton 并在 xib 中使用它?