Java 类com.google.android.gms.location.places.ui.PlaceAutocomplete 实例源码

项目:civify-app    文件:NavigateFragment.java   
private void handleSearch(int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Place place = PlaceAutocomplete.getPlace(getActivity(), data);
        Location loc = LocationAdapter.getLocation(place.getLatLng());
        try {
            CivifyMap.getInstance().disableLocation();
            CivifyMap.getInstance().setAutoCenter(false);
            mLastZoom = CivifyMap.getInstance().getCurrentCameraPosition().zoom;

            CivifyMap.getInstance().center(loc, CivifyMap.DEFAULT_ZOOM, true);
            mSarchCenterSnackbar = Snackbar.make(getView(),
                    getString(R.string.search_disable_center), Snackbar.LENGTH_INDEFINITE);
            mSarchCenterSnackbar.show();
        } catch (MapNotLoadedException ignore) {
            Snackbar.make(getView(), getString(R.string.error_ocurred),
                    Snackbar.LENGTH_SHORT).show();
        }
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
        Snackbar.make(getView(), getString(R.string.error_ocurred),
                Snackbar.LENGTH_SHORT).show();
    }
}
项目:AppGoogleMaps    文件:DirectionsDetailFragment.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode){
        case PLACE_AUTOCOMPLETE_REQUEST_CODE:
            if (resultCode == RESULT_OK) {
                Place place = PlaceAutocomplete.getPlace(getActivity(), data);
                showToast(place.getAddress().toString());
                Log.i("TAG", "Place: " + place.getName());
            } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
                Status status = PlaceAutocomplete.getStatus(getActivity(), data);
                // TODO: Handle the error.
                Log.i("TAG", status.getStatusMessage());
                showToast(status.getStatusMessage());
            } else if (resultCode == RESULT_CANCELED) {
                // The user canceled the operation.
                showToast("Operation canceled");
            }
            break;
    }
}
项目:bikedeboa-android    文件:MapActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            // Move camera to that place and add normal marker
            Place place = PlaceAutocomplete.getPlace(this, data);
            this.googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 17), 1000, null);
            this.googleMap.addMarker(new MarkerOptions().position(place.getLatLng()));
            // Set text on "edit text"
            binding.placeSearch.setText(place.getName());
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this, data);
            Log.w(TAG, status.getStatusMessage());
        } else if (resultCode == RESULT_CANCELED) {
            // The user canceled the operation -- clear text
            binding.placeSearch.setText("");
        }
    }
}
项目:mobile-app-dev-book    文件:NewJournalActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place pl = PlaceAutocomplete.getPlace(this, data);
            location.setText(pl.getAddress());
            Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress());

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status stat = PlaceAutocomplete.getStatus(this, data);
            Log.d(TAG, "onActivityResult: ");
        }
        else if (requestCode == RESULT_CANCELED){
            System.out.println("Cancelled by the user");
        }
    }
    else
        super.onActivityResult(requestCode, resultCode, data);
}
项目:mobile-app-dev-book    文件:NewJournalActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place pl = PlaceAutocomplete.getPlace(this, data);
            location.setText(pl.getName());
            currentTrip.location = pl.getName().toString();
            currentTrip.lat = pl.getLatLng().latitude;
            currentTrip.lng = pl.getLatLng().longitude;
            currentTrip.placeId = pl.getId();

            Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress());

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status stat = PlaceAutocomplete.getStatus(this, data);
            Log.d(TAG, "onActivityResult: ");
        }
        else if (requestCode == RESULT_CANCELED){
            System.out.println("Cancelled by the user");
        }
    }
    else
        super.onActivityResult(requestCode, resultCode, data);
}
项目:mobile-app-dev-book    文件:NewJournalActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place pl = PlaceAutocomplete.getPlace(this, data);
            location.setText(pl.getName());
            currentTrip.setLocation(pl.getName().toString());
            currentTrip.setLat(pl.getLatLng().latitude);
            currentTrip.setLng(pl.getLatLng().longitude);
            currentTrip.setPlaceId(pl.getId());

            Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress());

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status stat = PlaceAutocomplete.getStatus(this, data);
            Log.d(TAG, "onActivityResult: ");
        }
        else if (requestCode == RESULT_CANCELED){
            System.out.println("Cancelled by the user");
        }
    }
    else
        super.onActivityResult(requestCode, resultCode, data);
}
项目:mobile-app-dev-book    文件:NewJournalActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place pl = PlaceAutocomplete.getPlace(this, data);
            location.setText(pl.getName());
            currentTrip.setLocation(pl.getName().toString());
            currentTrip.setLat(pl.getLatLng().latitude);
            currentTrip.setLng(pl.getLatLng().longitude);
            currentTrip.setPlaceId(pl.getId());

            Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress());

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status stat = PlaceAutocomplete.getStatus(this, data);
            Log.d(TAG, "onActivityResult: ");
        }
        else if (requestCode == RESULT_CANCELED){
            System.out.println("Cancelled by the user");
        }
    }
    else
        super.onActivityResult(requestCode, resultCode, data);
}
项目:mobile-app-dev-book    文件:NewJournalActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place pl = PlaceAutocomplete.getPlace(this, data);
            location.setText(pl.getName());
            currentTrip.setLocation(pl.getName().toString());
            currentTrip.setLat(pl.getLatLng().latitude);
            currentTrip.setLng(pl.getLatLng().longitude);
            currentTrip.setPlaceId(pl.getId());

            Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress());

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status stat = PlaceAutocomplete.getStatus(this, data);
            Log.d(TAG, "onActivityResult: ");
        }
        else if (requestCode == RESULT_CANCELED){
            System.out.println("Cancelled by the user");
        }
    }
    else
        super.onActivityResult(requestCode, resultCode, data);
}
项目:mobile-app-dev-book    文件:TripEditorActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place pl = PlaceAutocomplete.getPlace(this, data);
            location.setText(pl.getName());
            currentTrip.setLocation(pl.getName().toString());
            currentTrip.setLat(pl.getLatLng().latitude);
            currentTrip.setLng(pl.getLatLng().longitude);
            currentTrip.setPlaceId(pl.getId());

            Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress());

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status stat = PlaceAutocomplete.getStatus(this, data);
            Log.d(TAG, "onActivityResult: ");
        }
        else if (requestCode == RESULT_CANCELED){
            System.out.println("Cancelled by the user");
        }
    }
    else
        super.onActivityResult(requestCode, resultCode, data);
}
项目:mobile-app-dev-book    文件:TripEditorActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place pl = PlaceAutocomplete.getPlace(this, data);
            location.setText(pl.getName());
            currentTrip.setLocation(pl.getName().toString());
            currentTrip.setLat(pl.getLatLng().latitude);
            currentTrip.setLng(pl.getLatLng().longitude);
            currentTrip.setPlaceId(pl.getId());

            Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress());

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status stat = PlaceAutocomplete.getStatus(this, data);
            Log.d(TAG, "onActivityResult: ");
        }
        else if (requestCode == RESULT_CANCELED){
            System.out.println("Cancelled by the user");
        }
    }
    else
        super.onActivityResult(requestCode, resultCode, data);
}
项目:directly    文件:ToiletListFragment.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    authorizer.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == LOCATION_ENABLE_REQUEST_CODE) {
            new Handler().post(() -> {
                toiletListPresenter.locationEnabledSuccess();
            });
        }
        if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
            Place place = PlaceAutocomplete.getPlace(getActivity(), data);
            toiletListPresenter.citySelected(place);
        }
    }


}
项目:cast-dashboard-android-app    文件:WeatherSettings.java   
@OnClick(R.id.weather_city)
public void selectCity() {

    //restrict to cities
    AutocompleteFilter cityFilter = new AutocompleteFilter.Builder()
            .setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES)
            .build();
    try {
        Intent intent =
                new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                        .setFilter(cityFilter)
                        .build(getActivity());
        startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        // TODO: Handle the error.
    }
}
项目:cast-dashboard-android-app    文件:WeatherSettings.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            Place place = PlaceAutocomplete.getPlace(getContext(), data);
            Log.i(MainActivity.TAG, "Place: " + place.getName());


            weatherLat.update(place.getLatLng().latitude);
            weatherLng.update(place.getLatLng().longitude);
            weatherCity.update(place.getName().toString());

            sWeatherCity.setSubHeaderText(weatherCity.value);

            // don't change the order of the following two lines
            updateWidgetProperty("lat", weatherLat.value);
            updateWidgetProperty("lng", weatherLng.value);

        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(getContext(), data);
            // TODO: Handle the error.
            Log.i(MainActivity.TAG, status.getStatusMessage());

        }
    }
}
项目:androidprojectbase    文件:PlacesAutoCompleteSample.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //autocompleteFragment.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place place = PlaceAutocomplete.getPlace(this, data);
            Log.i("1", "Place:" + place.toString());
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this, data);
            Log.i("1", status.getStatusMessage());
        } else if (requestCode == RESULT_CANCELED) {

        }
    }
}
项目:PlaceApiAutocompleteWidget    文件:MainActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_search) {
        // Method #3
        try {
            Intent intent = new PlaceAutocomplete.IntentBuilder
                    (PlaceAutocomplete.MODE_OVERLAY)
                    .setBoundsBias(BOUNDS_MOUNTAIN_VIEW)
                    .build(MainActivity.this);
            startActivityForResult(intent, REQUEST_SELECT_PLACE);
        } catch (GooglePlayServicesRepairableException |
                GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
项目:Addy-Android    文件:MapsActivity.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Log.d(TAG, "resultCode=" + Integer.toString(resultCode));
    //final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
    switch (resultCode) {
        case Activity.RESULT_OK: {
            // All required changes were successfully made
            // Log.i(TAG, "Location enabled by user!");
            if(requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE){
                Place place = PlaceAutocomplete.getPlace(this, data);
                Log.i(TAG, "Place: " + place.getLatLng());
                createMarkerLatLng(convert(place.getLatLng().latitude,place.getLatLng().longitude),place.getLatLng());
                Toast.makeText(getApplicationContext(),place.getName(),Toast.LENGTH_SHORT).show();
            }else {
                Toast.makeText(getApplicationContext(), "Location Enabled", Toast.LENGTH_SHORT).show();
                enableMyLocation();
                startActivity(new Intent(MapsActivity.this, MapsActivity.class));
            }break;
        }
        case Activity.RESULT_CANCELED: {
            // The user was asked to change settings, but chose not to
            //TODO: display the below code
            Toast.makeText(getApplicationContext(),"No Connection Found",Toast.LENGTH_SHORT).show();
            /*Snackbar snackbar = Snackbar.make(, "No Connection Found", Snackbar.LENGTH_INDEFINITE)
                    .setAction("GO OFFLINE", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {

                        }
                    });
            */// Log.i(TAG, "Location not enabled, user cancelled.");
            break;
        }
        default: {
            // Log.e(TAG, "Error in selecting the button in Auto-Switch On Location Feature");
            break;
        }
    }
}
项目:mapbox-navigation-hud-demo    文件:GeocodeActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
    if (resultCode == RESULT_OK) {
      Place place = PlaceAutocomplete.getPlace(this, data);
      Toast.makeText(this, "Place picked: " + place.getName(), Toast.LENGTH_SHORT).show();
      launchDisplay(place);
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
      Status status = PlaceAutocomplete.getStatus(this, data);
      Log.i(TAG, status.getStatusMessage());
    }
  }
}
项目:mapbox-navigation-hud-demo    文件:GeocodeActivity.java   
private void launchSearchAutocomplete() {
  try {
    Intent intent =
      new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
        .build(this);
    startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
  } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
    Log.e(TAG, e.getMessage());
  }
}
项目:AddyHINT17    文件:MapsActivity.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Log.d(TAG, "resultCode=" + Integer.toString(resultCode));
    //final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
    switch (resultCode) {
        case Activity.RESULT_OK: {
            // All required changes were successfully made
            // Log.i(TAG, "Location enabled by user!");
            if(requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE){
                Place place = PlaceAutocomplete.getPlace(this, data);
                Log.i(TAG, "Place: " + place.getLatLng());
                createMarkerLatLng(convert(place.getLatLng().latitude,place.getLatLng().longitude),place.getLatLng());
                Toast.makeText(getApplicationContext(),place.getName(),Toast.LENGTH_SHORT).show();
            }else {
                Toast.makeText(getApplicationContext(), "Location Enabled", Toast.LENGTH_SHORT).show();
                enableMyLocation();
                startActivity(new Intent(MapsActivity.this, MapsActivity.class));
            }break;
        }
        case Activity.RESULT_CANCELED: {
            // The user was asked to change settings, but chose not to
            //TODO: display the below code
            Toast.makeText(getApplicationContext(),"No Connection Found",Toast.LENGTH_SHORT).show();
            /*Snackbar snackbar = Snackbar.make(, "No Connection Found", Snackbar.LENGTH_INDEFINITE)
                    .setAction("GO OFFLINE", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {

                        }
                    });
            */// Log.i(TAG, "Location not enabled, user cancelled.");
            break;
        }
        default: {
            // Log.e(TAG, "Error in selecting the button in Auto-Switch On Location Feature");
            break;
        }
    }
}
项目:bikedeboa-android    文件:MapActivity.java   
@Override
public void onClick(View v) {
    try {
        // Launch autocomplete activity
        Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                .setFilter(new AutocompleteFilter.Builder()
                        .setCountry("BR")
                        .build())
                .build(MapActivity.this);
        startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        // TODO: Handle the error.
    }
}
项目:WeatherPlus    文件:CityListFragment.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case LOCATION_NAME_REQUEST:

            if (resultCode == RESULT_OK) {
                Log.d(TAG, "Add city name request to queue");

                Place place = PlaceAutocomplete.getPlace(getActivity(), data);
                LatLng coords = place.getLatLng();

                cityAddQueue.add(new CityCoordinatesModel(place.getName().toString(),
                        coords.latitude, coords.longitude));

                if (!isRefreshing && !isAddQueueHandling) {
                    Log.d(TAG, "Start new city name request queue");

                    makeCityNameWeatherRequest();
                }

                isAddQueueHandling = true;

            } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
                Status status = PlaceAutocomplete.getStatus(getActivity(), data);

                Log.d(TAG, status.getStatusMessage());
            }

            break;
    }
}
项目:directly    文件:NewToiletFragment.java   
public void showLocationChooser() {
    try {
        Intent intent =
                new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                        .build(getActivity());
        startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        Timber.e(e, "", "");
    }
}
项目:directly    文件:NewToiletFragment.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (resultCode == RESULT_OK) {
        if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
            Place place = PlaceAutocomplete.getPlace(getActivity(), intent);
            newToiletPresenter.placeSelected(place);
        }
    }
}
项目:directly    文件:ToiletListFragment.java   
public void showLocationChooser() {
    try {
        Intent intent =
                new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                        .build(getActivity());
        startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        Timber.e(e, "", "");
    }
}
项目:cast-dashboard-android-app    文件:MapSettings.java   
@OnClick(R.id.map_location)
public void getLocation() {
    try {
        Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY).build(getActivity());
        startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        Log.e(MainActivity.TAG, e.toString());
    }
}
项目:cast-dashboard-android-app    文件:MapSettings.java   
@OnClick(R.id.map_destination)
public void getDestination() {
    try {
        Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY).build(getActivity());
        startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE_DESTINATION);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        Log.e(MainActivity.TAG, e.toString());
    }
}
项目:Dryver    文件:ActivityRequestMap.java   
/**
 * Receives the data from {@link PlaceAutocomplete} search intent and moves the map to that location
 *
 * @param requestCode
 * @param resultCode
 * @param data
 * @see PlaceAutocomplete
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_SELECT_PLACE) {
        if (resultCode == RESULT_OK) {
            Place place = PlaceAutocomplete.getPlace(this, data);
            Location location = new Location("place");
            location.setLatitude(place.getLatLng().latitude);
            location.setLongitude(place.getLatLng().longitude);
            mapUtil.moveMap(mMap, location, 15);
        }
    }
}
项目:androidprojectbase    文件:PlacesAutoCompleteSample.java   
private void callPlaceAutocompleteActivityIntent() {
    try {
        // Change MODE for dialog PlaceAutocomplete.MODE_OVERLAY
        // Usage limits do not apply to the autocomplete widget.
        Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                        .build(this);
        startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
        // TODO: Handle the error.
    }

}
项目:PlaceApiAutocompleteWidget    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    locationTextView = (TextView) findViewById(R.id.txt_location);
    attributionsTextView = (TextView) findViewById(R.id.txt_attributions);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

    // Method #1
    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_fragment);
    autocompleteFragment.setOnPlaceSelectedListener(this);
    autocompleteFragment.setHint("Search a Location");
    autocompleteFragment.setBoundsBias(BOUNDS_MOUNTAIN_VIEW);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Method #2
            try {
                Intent intent = new PlaceAutocomplete.IntentBuilder
                        (PlaceAutocomplete.MODE_FULLSCREEN)
                        .setBoundsBias(BOUNDS_MOUNTAIN_VIEW)
                        .build(MainActivity.this);
                startActivityForResult(intent, REQUEST_SELECT_PLACE);
            } catch (GooglePlayServicesRepairableException |
                    GooglePlayServicesNotAvailableException e) {
                e.printStackTrace();
            }
        }
    });
}
项目:PlaceApiAutocompleteWidget    文件:MainActivity.java   
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_SELECT_PLACE) {
        if (resultCode == RESULT_OK) {
            Place place = PlaceAutocomplete.getPlace(this, data);
            this.onPlaceSelected(place);
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this, data);
            this.onError(status);
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
项目:android-play-places    文件:MainActivity.java   
/**
 * Called after the autocomplete activity has finished to return its result.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Check that the result was from the autocomplete widget.
    if (requestCode == REQUEST_CODE_AUTOCOMPLETE) {
        if (resultCode == RESULT_OK) {
            // Get the user's selected place from the Intent.
            Place place = PlaceAutocomplete.getPlace(this, data);
            Log.i(TAG, "Place Selected: " + place.getName());

            // Format the place's details and display them in the TextView.
            mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(),
                    place.getId(), place.getAddress(), place.getPhoneNumber(),
                    place.getWebsiteUri()));

            // Display attributions if required.
            CharSequence attributions = place.getAttributions();
            if (!TextUtils.isEmpty(attributions)) {
                mPlaceAttribution.setText(Html.fromHtml(attributions.toString()));
            } else {
                mPlaceAttribution.setText("");
            }
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this, data);
            Log.e(TAG, "Error: Status = " + status.toString());
        } else if (resultCode == RESULT_CANCELED) {
            // Indicates that the activity closed before a selection was made. For example if
            // the user pressed the back button.
        }
    }
}