繁体   English   中英

Android Google地址自动完成PendingResult永远等待

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM