use of com.google.android.libraries.places.widget.Autocomplete in project android-places-demos by googlemaps.
the class PlaceAutocompleteActivity method programmaticPlacePredictions.
// [END maps_places_on_activity_result]
private void programmaticPlacePredictions(String query) {
// [START maps_places_programmatic_place_predictions]
// Create a new token for the autocomplete session. Pass this to FindAutocompletePredictionsRequest,
// and once again when the user makes a selection (for example when calling fetchPlace()).
AutocompleteSessionToken token = AutocompleteSessionToken.newInstance();
// Create a RectangularBounds object.
RectangularBounds bounds = RectangularBounds.newInstance(new LatLng(-33.880490, 151.184363), new LatLng(-33.858754, 151.229596));
// Use the builder to create a FindAutocompletePredictionsRequest.
FindAutocompletePredictionsRequest request = FindAutocompletePredictionsRequest.builder().setLocationBias(bounds).setOrigin(new LatLng(-33.8749937, 151.2041382)).setCountries("AU", "NZ").setTypeFilter(TypeFilter.ADDRESS).setSessionToken(token).setQuery(query).build();
placesClient.findAutocompletePredictions(request).addOnSuccessListener((response) -> {
for (AutocompletePrediction prediction : response.getAutocompletePredictions()) {
Log.i(TAG, prediction.getPlaceId());
Log.i(TAG, prediction.getPrimaryText(null).toString());
}
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e(TAG, "Place not found: " + apiException.getStatusCode());
}
});
// [END maps_places_programmatic_place_predictions]
}
use of com.google.android.libraries.places.widget.Autocomplete in project android-places-demos by googlemaps.
the class PlaceAutocompleteActivity method startAutocompleteIntent.
// [START_EXCLUDE silent]
private void startAutocompleteIntent() {
// [END_EXCLUDE]
// Set the fields to specify which types of place data to
// return after the user has made a selection.
List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Start the autocomplete intent.
Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields).build(this);
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);
// [END maps_places_autocomplete_intent]
}
Aggregations