2017-04-14 47 views
4

我在我的應用程序中實現地方自動填充,並在EditText中編寫搜索關鍵字以根據搜索地點關鍵字獲取結果。 這裏開始PlaceAutocomplete活動代碼搜索的地方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) { 
} 

當活動啓動列表顯示空白。

enter image description here

我want- 已經搜查的地方應該是演出活動時推出像Uber應用

enter image description here

回答

3

你必須持久內部應用程序存儲在您自動完成結果(共享偏好,數據庫..)或者你想要的地方。基本上,你需要自己實現你的UI。我不認爲你可以根據你的需求定製PlaceAutocomplete.IntentBuilder

  1. 實現API呼叫的AutocompleteGooglePlaces(我們使用的是此改造)

    @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); 
    
  2. 執行呼叫(上輸入點擊或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<>(); 
        } 
    
  3. 持久的結果自動完成結果GoogleAutocompleteResponse在您的應用程序中,並實現在UI中顯示結果或在ListView中填充的邏輯

+0

我可以自定義地方的自動完成,但我想要本地谷歌地方代碼 –

+1

沒有「本地谷歌地方」代碼爲此行爲。你必須自己實現它。快樂編碼;) – longilong

+1

您可以使用GeoDataApi.getAutocompletePredictions()[https://developers.google.com/places/android-api/autocomplete#get_place_predictions_programmatically]讓原生Android API – BhalchandraSW

相關問題