<fragment android:id="@+id/place_autocomplete_fragment" android:layout_width="match_parent" android:layout_height="wrap_content"android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
// PlaceAutocompleteFragment fragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);fragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { @Override public void onPlaceSelected(Place place) { // Handle the selected Place } @Override public void onError(Status status) { // Handle the error }
try { Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) .build(this); startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);} catch (GooglePlayServicesRepairableException e) { GooglePlayServicesUtil .getErrorDialog(e.getConnectionStatusCode(), getActivity(), 0);} catch (GooglePlayServicesNotAvailableException e) { // Handle the exception}
@interface MyViewController () @end@implementation ViewController...- (IBAction)onLaunchClicked:(id)sender { // Present the Autocomplete view controller when the button is pressed. GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init]; acController.delegate = self; [self presentViewController:acController animated:YES completion:nil];}- (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithPlace:(GMSPlace *)place { // The user has selected a place. [self dismissViewControllerAnimated:YES completion:nil];}- (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithError:(NSError *)error { [self dismissViewControllerAnimated:YES completion:nil];}// User pressed cancel button.- (void)wasCancelled:(GMSAutocompleteViewController *)viewController { [self dismissViewControllerAnimated:YES completion:nil];}@end
import UIKitimport GoogleMapsclass MyViewController: UIViewController { @IBAction func onLaunchClicked(sender: AnyObject) { let acController = GMSAutocompleteViewController() acController.delegate = self self.presentViewController(acController, animated: true, completion: nil) }}extension MyViewController: GMSAutocompleteViewControllerDelegate { func viewController(viewController: GMSAutocompleteViewController!, didAutocompleteWithPlace place: GMSPlace!) { // The user has selected a place. self.dismissViewControllerAnimated(true, completion: nil) } func viewController(viewController: GMSAutocompleteViewController!, didAutocompleteWithError error: NSError!) { self.dismissViewControllerAnimated(true, completion: nil) } func wasCancelled(viewController: GMSAutocompleteViewController!) { self.dismissViewControllerAnimated(true, completion: nil) }}
Give us feedback in our Product Forums.