[英]Android Google address autocomplete PendingResult awaits forever
我和我的項目小組成員正在嘗試使用適用於Android的Google API獲取自動完成地址。 到目前為止,我們正在嘗試用一個單詞對其進行測試,而不必擔心在autoCompleteView中添加一個偵聽器。 無論如何,我們無法進行首次測試。 我們的GoogleAPIClient設置如下:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Places.GEO_DATA_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
我們有一個連接偵聽器,如下所示:
@Override
public void onConnected(Bundle connectionHint) {
new GetPredictions().execute("boulevard");
}
最后(嗯,不是最后,但這是我們的代碼在等待之前被阻塞的程度),我們的AsyncTask類GetPredictions有一個doInBackground方法,如下所示:
@Override
protected AutocompletePredictionBuffer doInBackground(String... test) {
LatLng sudOuestLyon = new LatLng(45.708931, 4.745801);
LatLng nordEstLyon = new LatLng(45.805918, 4.924447);
LatLngBounds rectangleLyon = new LatLngBounds(sudOuestLyon, nordEstLyon);
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, test[0],
rectangleLyon, null);
AutocompletePredictionBuffer autocompletePredictions = results
.await();
return autocompletePredictions;
}
調試之后,我們看到我們陷入了“等待”狀態(並且限時版本超時)。 我們嘗試給它一些時間(幾分鍾),但是該應用程序沒有通過這種方法。 研究區(rectangleLyon)是一個矩形,覆蓋了法國里昂市和部分周圍地區。 這不是一個很大的區域,也沒有太多的林蔭大道,因此我們認為在其中搜索“林蔭大道”將很快返回結果。 我們懷疑GoogleApiClient可能配置不正確,但可以連接,因為我們傳入了僅通過OnConnected調用的方法,並且錯誤的請求最初不會返回PendingResult,對嗎?
為什么此代碼卡在results.await()
?
因此,經過更多搜索后,問題出在清單中的自動行以聲明鍵。 密鑰聲明必須具有“ android:name =“ com.google.android.geo.API_KEY”,而不是原始名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.