Android Place Autocomplete, how to get default search list by default

I implement an autocomplete location in my application and write the search keyword in EditTextto get the result according to the search keyword. here is the code to run PlaceAutocomplete activity to find a place

int PLACE_AUTOCOMPLETE_REQUEST_CODE = 1;
try {
Intent intent =
        new 
 PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                .build(this);
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
} catch (GooglePlayServicesRepairableException e) {
} catch (GooglePlayServicesNotAvailableException e) {
}

when the activity start list is empty.

enter image description here

What I want - the already found place should be displayed when the activity starts, for example, uber app

enter image description here

+4
source share
1 answer

( , ..) . , . , PlaceAutocomplete.IntentBuilder .

  • API- GooglePlaces ( )

    @GET("/maps/api/place/autocomplete/json")
    Call<GoogleAutocompleteResponse> getAutoCompleteSearchResults(@Query("key") String apiKey,
              @Query("input") String searchTerm,
              @Query("location") String location,
              @Query("radius") long radius);
    
  • ( Enter onTextChange)

    public List<GooglePlaceAutocompleteGeoModel> getAutoCompleteSearchResults(String searchTerm, LatLng center, long radius) {
    
       Call<GoogleAutocompleteResponse> call = googlePlacesRestApiService.getAutoCompleteSearchResults(API_KEY, searchTerm, getLocationStringFrom(center), radius);
    
        try {
            GoogleAutocompleteResponse autocompleteResponse = call.execute().body();
           List<GooglePlaceAutocompleteGeoModel> autocompleteResponsePredictions = autocompleteResponse.getPredictions();
           //Here are your Autocomplete Objects
           return autocompleteResponsePredictions;
    
       } catch (IOException e) {
           L.e("Error on Google Autocomplete call: " + e.getMessage());
       }
    
       return new ArrayList<>();
       }
    
  • GoogleAutocompleteResponse ListView

+3

Source: https://habr.com/ru/post/1674826/


All Articles