ios - 限制 Google AutoComplete API 仅显示附近的位置

标签 ios objective-c google-maps autocomplete ios9

对于位置查找,Google AutoComplete 效果很好,但它会返回世界各地的搜索结果。我想将搜索结果限制在 1000 米半径内或城市内。我跟着这个google link集成自动完成搜索。项目中仅使用以下代码

-(void)autoComplete
{
    GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
    acController.delegate = self;
 [self presentViewController:acController animated:YES completion:nil];
}
// Handle the user's selection.
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
    [self dismissViewControllerAnimated:YES completion:nil];
    // Do something with the selected place.
    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place attributions %@", place.attributions.string);
}

- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithError:(NSError *)error {
    [self dismissViewControllerAnimated:YES completion:nil];
    // TODO: handle the error.
    NSLog(@"Error: %@", [error description]);
}

// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
    [self dismissViewControllerAnimated:YES completion:nil];
}

最佳答案

你不能100%限制它,但是你可以通过指定它的东北角和西南角来给你的城市更多的优先权,代码如下

GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;

CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(northEastLati, northEastLongi);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(southWestLati, southWestLongi);
acController.autocompleteBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
                                                                            coordinate:southWest];

[self presentViewController:acController animated:YES completion:nil];

现在您将获得 99% 的结果将属于您的城市。希望对您有所帮助。

关于ios - 限制 Google AutoComplete API 仅显示附近的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34876020/

相关文章:

ios - 将 .3ds/.obj/.max/etc 文件导入 Cocos3D 项目

javascript - javascript 中的谷歌地图在第二次点击时不起作用

ios - 使用 UIWebView 的 GMSMarker 自定义信息窗口

ios - 从自定义 UITableViewCell 委托(delegate) TabBar

ios - 当我的 UITableView 尝试加载时,为什么我会收到有关无法出队的错误?

ios - 在按Return或Done键后将文本保存在UITextField上

javascript - 为默认打开谷歌地图的所有移动设备创建一个链接

ios - 在 Swift 中连接 UITableViewCell 标签

ios - 适用于 ios OAuth2、API V2 的 LinkedIn 登录。如何打开已安装的领英应用

iphone - nsdate 转换的问题