android Place Autocomplete 如何让搜索到的地点列表默认置顶
android Place Autocomplete how to get list of searched place on top by default
我在我的应用程序中实现了地点自动完成,并在 EditText
中写入搜索关键字以根据搜索地点关键字获得结果。
这里是启动 PlaceAutocomplete activity 以搜索 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) {
}
当 activity 启动列表显示空白时。
我想要的-
当 activity 像 uber app
一样启动时应该显示已经搜索过的地方
您必须在内部应用存储(共享首选项、数据库..)或您想要的地方保存您的自动完成结果。基本上,您需要自己实施 UI。我认为您无法根据需要自定义 PlaceAutocomplete.IntentBuilder
。
实施 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);
执行调用(在 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
中填充结果的逻辑
我在我的应用程序中实现了地点自动完成,并在 EditText
中写入搜索关键字以根据搜索地点关键字获得结果。
这里是启动 PlaceAutocomplete activity 以搜索 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) {
}
当 activity 启动列表显示空白时。
我想要的- 当 activity 像 uber app
一样启动时应该显示已经搜索过的地方您必须在内部应用存储(共享首选项、数据库..)或您想要的地方保存您的自动完成结果。基本上,您需要自己实施 UI。我认为您无法根据需要自定义 PlaceAutocomplete.IntentBuilder
。
实施 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);
执行调用(在 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 中填充结果的逻辑