Reputation: 305
I am working with GMSAutocompleteViewController
where i have three UITextfield
in my uiviewcontroller
. When first UItextfield
is click i move to GMSAutocompleteViewController
with tag number, but now i want to display place name in textfield which is click by user in gmsautocompleteviewcontroller
method. Please look at my code.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"start editing");
if (textField.tag ==1) {
NSLog(@"first");
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
else if (textField.tag ==2)
{
NSLog(@"second");
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
else if (textField.tag ==3)
{
NSLog(@"third");
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);
value = 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];
}
Upvotes: 2
Views: 1153
Reputation: 1236
declare globally a textfield
UITextField *tappedTextField;
check below code
- (void)textFieldDidBeginEditing:(UITextField *)textField{
tappedTextField = textField;
}
//gmsautocomplete delegate
- (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];
}
Upvotes: 2