你好我正在GMSAutocompleteViewController在我的应用程序工作。我有一个uitextfield在我的视图控制器时,我tapp textfield搜索使用谷歌API的地方,一个新的视图是开放的,由谷歌供电。请看我的代码。如何在uitextfield上应用自定义搜索,以便使用gmsAutocomplete视图控制器进行搜索。
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
tappedTextField = textField;
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
// Do something with the selected place.
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
NSLog(@"lat and log%f", place.coordinate.latitude);
NSLog(@"lang %f", place.coordinate.longitude);
tappedTextField.text = place.name;
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error {
// TODO: handle the error.
NSLog(@"error: %ld", (long)[error code]);
[self dismissViewControllerAnimated:YES completion:nil];
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
NSLog(@"Autocomplete was cancelled.");
[self dismissViewControllerAnimated:YES completion:nil];
}
我不想要移动到另一种观点认为在文本框TAPP进行搜索。有可能我只能从文本字段中搜索地点吗?
当我在目的地文本框单击一个新的观点出现了搜索,但我只需要请TAPP文本字段后,屏幕从文本框进行搜索。
有没有可能做这个任务,或者我总是使用视图由谷歌只提供动力? –
嗨它解决了吗? –