2017-04-14 11 views
4

私のアプリケーションに場所の自動補完を実装し、検索場所キーワードに従って結果を得るためにEditTextに検索キーワードを書き込みます。ここ 活動の打ち上げリストが空白に表示するときに場所android検索場所のリストをデフォルトで最上部に表示する方法

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) { 
} 

を検索するための開始PlaceAutocomplete活動のためのコード。内部アプリのストレージ内の永続的なあなたのオートコンプリートの結果(共有の好みにあなたが持っているユーバーアプリのような活動の打ち上げ

enter image description here

答えて

3

私は はすでに場所を検索want-するショーでなければなりません

enter image description here

データベース..)またはあなたが望むどこか。基本的には、自分でUIを実装する必要があります。あなたのニーズに合わせてPlaceAutocomplete.IntentBuilderをカスタマイズすることはできません。

  1. (入力クリックするか、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<>(); 
        } 
    
  2. 永続的に結果を実行し

    @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); 
    
  3. (私たちは、このために改造を使用している)AutocompleteGooglePlaces用APIコールを実装あなたのアプリ内に自動完成結果GoogleAutocompleteResponseがあり、UIで結果を表示するためのロジックを実装するか、ListView内に値を設定します

+0

私は場所のオートコンプリートをカスタマイズできますが、ネイティブのGoogleプレイスコード –

+1

にはこの動作のための「ネイティブgoogle place」コードはありません。あなたはそれを自分で実装する必要があります。ハッピーコーディング;) – longilong

+1

ネイティブAndroid APIを使用するために、GeoDataApi.getAutocompletePredictions()[https://developers.google.com/places/android-api/autocomplete#get_place_predictions_programmatically]を使用することができます – BhalchandraSW

関連する問題