当我在AutoCompleteTextView(mSearchText)中键入文本时,自动完成预测不会显示在MapsActivity中。
我尝试通过以下链接遵循该教程:https : //www.youtube.com/watch?v=6Trdd9EnmqY&list=PLgCYzUzKIBE-vInwQhGSdnbyJ62nixHCt&index=8。最近已弃用了其中使用的某些方法,因此我检查了https://developers.google.com/places/android-sdk/autocomplete上的文档,尤其是“以编程方式获取位置预测”和“迁移到New Places SDK客户端” 。我还遵循了同一个人的指南来设置我的API密钥,我认为这不应该成为问题。这是我的第一个Android应用程序,也是我对此网站的第一个问题,请耐心等待。
Places.initialize(getApplicationContext(), getString(R.string.google_maps_API_key));
PlacesClient placesClient = Places.createClient(this);
FindAutocompletePredictionsRequest request = FindAutocompletePredictionsRequest.builder()
.setLocationBias(RECTANGULAR_BOUNDS)
.setQuery(mSearchText.getText().toString())
.build();
placesClient.findAutocompletePredictions(request).addOnSuccessListener((response) -> {
for (AutocompletePrediction prediction : response.getAutocompletePredictions()) {
Log.i(TAG, prediction.getPlaceId());
Log.i(TAG, prediction.getPrimaryText(null).toString());
}
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e(TAG, "Place not found: " + apiException.getStatusCode());
}
});
Run Code Online (Sandbox Code Playgroud)
当用户在搜索栏中键入内容时,自动完成预测将显示出来,但这不会发生。我也听不到任何日志。