任何人都可以指导我在完成将 GoogleMaps 的 pod 安装到项目中的所有步骤后如何在 GoogleMap 中使用 place auto complete 吗?我对此一无所知,请有人帮助我!!!
最佳答案
希望你已经成功集成了 google pod
导入谷歌地图类
@import GoogleMaps;
添加委托(delegate)
<GMSAutocompleteViewControllerDelegate>
我的屏幕上有一个用于自动完成屏幕的按钮。 在按钮 IBAction 上写这段代码
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
并实现 GMSAutocompleteViewControllerDelegate
- (void)viewController:(GMSAutocompleteViewController *)viewControllerdidAutocompleteWithPlace:(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 *)viewControllerdidFailAutocompleteWithError:(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];
}
// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController*)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController*)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
关于ios - 为 GoogleMap objective-c 调用 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38473443/