对于位置查找,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/