我在我的应用程序中实现了地方自动完成功能,并在EditText中编写了搜索关键字,以根据搜索地点关键字获取结果.
这里是用于搜索PlaceAutocomplete活动的代码
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) {
}
当活动启动列表显示空白时.
我想要的是-
已经搜索过的地方应该在活动启动时显示为超级应用程序
解决方法:
您必须在内部应用程序存储(共享首选项,数据库..)或您想要的任何地方保留自动完成结果.基本上,您需要自己实现UI.我认为您无法根据需要自定义PlaceAutocomplete.IntentBuilder.
>为AutocompleteGooglePlaces实施API调用(我们正在为此进行改造)
@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-click或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的结果并实现逻辑以在UI中显示结果或填充在ListView中