2017-04-14 9 views
4

내 응용 프로그램에 장소 자동 완성 기능을 구현하고 검색 장소 키워드에 따라 결과를 얻으려면 EditText에 검색 키워드를 씁니다. 활동 출시 목록 빈 표시 할 때 여기에서 시작 PlaceAutocomplete 활동에 대한 코드가 장소android 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) { 
} 

검색 할 수 있습니다.

enter image description here

내가 가 이미이 표시되어야합니다 검색 want- 어떤 때 동네 짱 응용 프로그램과 같은 활동 시작 당신은 당신의 자동 완성 내부 응용 프로그램 저장 내 결과 (공유 환경 지속에있는

enter image description here

답변

3

, 데이터베이스 ..) 또는 원하는 곳에서. 기본적으로 UI를 직접 구현해야합니다. 귀하의 필요에 맞게 PlaceAutocomplete.IntentBuilder을 사용자 정의 할 수 있다고 생각하지 않습니다.

  1. 는 결과

    @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. 영구 (우리는이에 대한 개조를 사용하는) AutocompleteGooglePlaces에 대한 API-전화를 구현 자동 완성 결과가 앱 내에 GoogleAutocompleteResponse이고 UI에 결과를 표시하거나 ListView 내에 채워지는 로직을 구현하십시오

+0

내가 장소 자동 완성을 사용자 정의 할 수 있지만 기본 Google 지역 코드 –

+1

에이 동작에 대한 "기본 Google 장소"코드가 필요하지 않습니다. 직접 구현해야합니다. 행복한 코딩;) – longilong

+1

기본 Android API를 사용하려면 GeoDataApi.getAutocompletePredictions() [https://developers.google.com/places/android-api/autocomplete#get_place_predictions_programmatically]를 사용할 수 있습니다. – BhalchandraSW