你好我正在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文本字段後,屏幕從文本框進行搜索。
有沒有可能做這個任務,或者我總是使用視圖由谷歌只提供動力? –
嗨它解決了嗎? –