2017-04-14 128 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