use of com.android.volley.Request.Method in project android-places-demos by googlemaps.
the class ProgrammaticAutocompleteToolbarActivity method getPlacePredictions.
/**
* This method demonstrates the programmatic approach to getting place predictions. The
* parameters in this request are currently biased to Kolkata, India.
*
* @param query the plus code query string (e.g. "GCG2+3M K")
*/
private void getPlacePredictions(String query) {
// The value of 'bias' biases prediction results to the rectangular region provided
// (currently Kolkata). Modify these values to get results for another area. Make sure to
// pass in the appropriate value/s for .setCountries() in the
// FindAutocompletePredictionsRequest.Builder object as well.
final LocationBias bias = RectangularBounds.newInstance(// SW lat, lng
new LatLng(22.458744, 88.208162), // NE lat, lng
new LatLng(22.730671, 88.524896));
// Create a new programmatic Place Autocomplete request in Places SDK for Android
final FindAutocompletePredictionsRequest newRequest = FindAutocompletePredictionsRequest.builder().setSessionToken(sessionToken).setLocationBias(bias).setTypeFilter(TypeFilter.ESTABLISHMENT).setQuery(query).setCountries("IN").build();
// Perform autocomplete predictions request
placesClient.findAutocompletePredictions(newRequest).addOnSuccessListener((response) -> {
List<AutocompletePrediction> predictions = response.getAutocompletePredictions();
adapter.setPredictions(predictions);
progressBar.setIndeterminate(false);
viewAnimator.setDisplayedChild(predictions.isEmpty() ? 0 : 1);
}).addOnFailureListener((exception) -> {
progressBar.setIndeterminate(false);
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e(TAG, "Place not found: " + apiException.getStatusCode());
}
});
}
Aggregations