Search in sources :

Example 1 with AutocompleteSupportFragment

use of com.google.android.libraries.places.widget.AutocompleteSupportFragment 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]
}
Also used : Status(com.google.android.gms.common.api.Status) ArrayList(java.util.ArrayList) AutocompleteSupportFragment(com.google.android.libraries.places.widget.AutocompleteSupportFragment) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) PlaceSelectionListener(com.google.android.libraries.places.widget.listener.PlaceSelectionListener) Place(com.google.android.libraries.places.api.model.Place)

Example 2 with AutocompleteSupportFragment

use of com.google.android.libraries.places.widget.AutocompleteSupportFragment 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());
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) AutocompleteSupportFragment(com.google.android.libraries.places.widget.AutocompleteSupportFragment) Event(com.eventyay.organizer.data.event.Event) PlaceSelectionListener(com.google.android.libraries.places.widget.listener.PlaceSelectionListener) Place(com.google.android.libraries.places.api.model.Place)

Example 3 with AutocompleteSupportFragment

use of com.google.android.libraries.places.widget.AutocompleteSupportFragment 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());
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) AutocompleteSupportFragment(com.google.android.libraries.places.widget.AutocompleteSupportFragment) Event(com.eventyay.organizer.data.event.Event) PlaceSelectionListener(com.google.android.libraries.places.widget.listener.PlaceSelectionListener) Place(com.google.android.libraries.places.api.model.Place)

Example 4 with AutocompleteSupportFragment

use of com.google.android.libraries.places.widget.AutocompleteSupportFragment in project android-places-demos by googlemaps.

the class AutocompleteTestActivity method setupAutocompleteSupportFragment.

private void setupAutocompleteSupportFragment() {
    final AutocompleteSupportFragment autocompleteSupportFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_support_fragment);
    autocompleteSupportFragment.setPlaceFields(getPlaceFields());
    autocompleteSupportFragment.setOnPlaceSelectedListener(getPlaceSelectionListener());
    findViewById(R.id.autocomplete_support_fragment_update_button).setOnClickListener(view -> autocompleteSupportFragment.setPlaceFields(getPlaceFields()).setText(getQuery()).setHint(getHint()).setCountries(getCountries()).setLocationBias(getLocationBias()).setLocationRestriction(getLocationRestriction()).setTypeFilter(getTypeFilter()).setActivityMode(getMode()));
}
Also used : AutocompleteSupportFragment(com.google.android.libraries.places.widget.AutocompleteSupportFragment)

Aggregations

AutocompleteSupportFragment (com.google.android.libraries.places.widget.AutocompleteSupportFragment)4 Status (com.google.android.gms.common.api.Status)3 Place (com.google.android.libraries.places.api.model.Place)3 PlaceSelectionListener (com.google.android.libraries.places.widget.listener.PlaceSelectionListener)3 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageManager (android.content.pm.PackageManager)2 Bundle (android.os.Bundle)2 Event (com.eventyay.organizer.data.event.Event)2 Intent (android.content.Intent)1 LatLng (com.google.android.gms.maps.model.LatLng)1 ArrayList (java.util.ArrayList)1