限制Google AutoComplete API只显示附近的位置 [英] Restrict the Google AutoComplete API to show only nearby locations

查看:336
本文介绍了限制Google AutoComplete API只显示附近的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于位置查找Google AutoComplete的效果很好,但它将搜索结果返回到全世界。我想限制在1000米范围内或在城市中的搜索结果。我遵循此谷歌链接来集成自动完成搜索。只有以下代码在项目中使用

For location finding Google AutoComplete works good but its returning the search results all over the world. I want to restrict the search results either with in the 1000 meter radius or in a city. I followed this google link to integrate the autocomplete search. Only this below code used in project

-(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];
}


推荐答案

,但您可以通过指定其东北角和西南角来优先考虑您的城市,以下是代码:

You cannot 100% restrict it, But you can give more priority to your city by specifying its northeast and southwest corners, Here is the code

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%的结果将归属于您的城市。希望它能帮助你。

Now you will get 99% of result will be belongs to your city. Hope it will help you.

这篇关于限制Google AutoComplete API只显示附近的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆