gpt4 book ai didi

ios - 将搜索栏添加到Google Place Picker(GMSPlacePicker)

转载 作者:行者123 更新时间:2023-12-01 18:45:49 24 4
gpt4 key购买 nike

我是iOS应用程序开发人员的新手。我正在使用Google地点选择器(GMSPlacePicker),看起来不错,但没有看到搜索栏。我应该如何添加搜索栏?我指的是https://developers.google.com/places/ios-api/placepicker,他们正在提供有关https://developers.google.com/places/ios-api/autocomplete#add_an_autocomplete_ui_control的文档,但是我很困惑如何在 objective-c 中实现GMSAutocompleteViewControllerGMSAutocompleteResultsViewController
谁能帮帮我吗?
谢谢

最佳答案

- (IBAction)onLaunchClicked:(id)sender {

if ([_textField.text length] > 0) {
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}else {
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Message" message:@"Enter a name" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];
[controller addAction:action];
[self presentViewController:controller 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);

[_peopleArray addObject:@{@"name":_textField.text,
@"place":place.name,
@"lat":[NSString stringWithFormat:@"%0.6f",place.coordinate.latitude],
@"long":[NSString stringWithFormat:@"%0.6f",place.coordinate.longitude]}];
[_tableView reloadData];
_textField.text = @"";
}

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

关于ios - 将搜索栏添加到Google Place Picker(GMSPlacePicker),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36172188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com