将搜索栏添加到Google地方选择器(GMSPlacePicker)

时间:2016-03-23 07:33:50

标签: ios objective-c google-places-api gmsautocomplete gmsplacepicker

我是iOS应用程序开发人员的新手。我正在使用谷歌地方选择器(GMSPlacePicker),它看起来很好,但没有看到搜索栏。我该如何添加搜索栏?我指的是https://developers.google.com/places/ios-api/placepicker,他们正在https://developers.google.com/places/ios-api/autocomplete#add_an_autocomplete_ui_control提供文件,但我很困惑如何在目标C中实施GMSAutocompleteViewControllerGMSAutocompleteResultsViewController。 有人可以帮帮我吗?

由于

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

我已经解决了这个问题。我刚刚更新 GoogleMaps.framework