小编san*_*mar的帖子

如何使用gmsAutocomplete视图控制器在uitextfield上应用自定义搜索以进行地点搜索.

我正在我的应用程序中使用GMSAutocompleteViewController.我在视图控制器中有一个uitextfield当我使用谷歌api搜索文本字段搜索一个地方时,一个新视图打开,由谷歌提供支持.请看我的代码.

- (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];
     } …
Run Code Online (Sandbox Code Playgroud)

google-maps autocomplete ios

5
推荐指数
1
解决办法
4074
查看次数

标签 统计

autocomplete ×1

google-maps ×1

ios ×1