<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) { // 選択したプレイスを処理 } @Override public void onError(Status status) { // エラーを処理 }
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) { // 例外を処理 }
@interface MyViewController () @end @implementation ViewController . . . - (IBAction)onLaunchClicked:(id)sender { // ボタン押下時にオートコンプリート ビュー コントローラーを表示 GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init]; acController.delegate = self; [self presentViewController:acController animated:YES completion:nil]; } - (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithPlace:(GMSPlace *)place { // ユーザーがプレイスを選択 [self dismissViewControllerAnimated:YES completion:nil]; } - (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithError:(NSError *)error { [self dismissViewControllerAnimated:YES completion:nil]; } // ユーザーがキャンセル ボタンを押下 - (void)wasCancelled:(GMSAutocompleteViewController *)viewController { [self dismissViewControllerAnimated:YES completion:nil]; } @end
import UIKit import GoogleMaps class 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!) { // ユーザーがプレイスを選択 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) } }