use of com.google.android.libraries.places.widget.listener.PlaceSelectionListener in project android-places-demos by googlemaps.
the class PlaceAutocompleteActivity method initAutocompleteSupportFragment.
private void initAutocompleteSupportFragment() {
// [START maps_places_autocomplete_support_fragment]
// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
// Specify the types of place data to return.
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(@NotNull Place place) {
// TODO: Get info about the selected place.
Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
}
@Override
public void onError(@NotNull Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " + status);
}
});
// [END maps_places_autocomplete_support_fragment]
// [START maps_places_autocomplete_location_bias]
autocompleteFragment.setLocationBias(RectangularBounds.newInstance(new LatLng(-33.880490, 151.184363), new LatLng(-33.858754, 151.229596)));
// [END maps_places_autocomplete_location_bias]
// [START maps_places_autocomplete_location_restriction]
autocompleteFragment.setLocationRestriction(RectangularBounds.newInstance(new LatLng(-33.880490, 151.184363), new LatLng(-33.858754, 151.229596)));
// [END maps_places_autocomplete_location_restriction]
// [START maps_places_autocomplete_type_filter]
autocompleteFragment.setTypeFilter(TypeFilter.ADDRESS);
// [END maps_places_autocomplete_type_filter]
List<Place.Field> fields = new ArrayList<>();
// [START maps_places_intent_type_filter]
Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields).setTypeFilter(TypeFilter.ADDRESS).build(this);
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);
// [END maps_places_intent_type_filter]
// [START maps_places_autocomplete_country_filter]
autocompleteFragment.setCountries("AU", "NZ");
// [END maps_places_autocomplete_country_filter]
}
use of com.google.android.libraries.places.widget.listener.PlaceSelectionListener in project open-event-orga-app by fossasia.
the class UpdateEventFragment method setupPlacesAutocomplete.
private void setupPlacesAutocomplete() {
ApplicationInfo ai = null;
try {
ai = getContext().getPackageManager().getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Bundle bundle = ai.metaData;
String placesApiKey = bundle.getString("com.google.android.geo.API_KEY");
Places.initialize(getActivity().getApplicationContext(), placesApiKey);
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment) getChildFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG, Place.Field.ADDRESS));
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Timber.d(place.getAddress());
Event event = binding.getEvent();
event.latitude = place.getLatLng().latitude;
event.longitude = place.getLatLng().longitude;
event.locationName = place.getAddress();
event.searchableLocationName = place.getName();
}
@Override
public void onError(Status status) {
ViewUtils.showSnackbar(binding.getRoot(), status.getStatusMessage());
}
});
}
use of com.google.android.libraries.places.widget.listener.PlaceSelectionListener in project open-event-orga-app by fossasia.
the class EventDetailsStepOne method setupPlacesAutocomplete.
private void setupPlacesAutocomplete() {
ApplicationInfo ai = null;
try {
ai = getContext().getPackageManager().getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Bundle bundle = ai.metaData;
String placesApiKey = bundle.getString("com.google.android.geo.API_KEY");
Places.initialize(getActivity().getApplicationContext(), placesApiKey);
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment) getChildFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG, Place.Field.ADDRESS));
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Timber.d(place.getAddress());
Event event = binding.getEvent();
event.latitude = place.getLatLng().latitude;
event.longitude = place.getLatLng().longitude;
event.locationName = place.getAddress();
event.searchableLocationName = place.getName();
}
@Override
public void onError(Status status) {
ViewUtils.showSnackbar(binding.getRoot(), status.getStatusMessage());
}
});
}
Aggregations