【问题标题】:Google Places api AutocompletePrediction prediction.getDescription() MissingAfter upgrading to Play services to 9.4.0Google Places api AutocompletePrediction prediction.getDescription() MissingAfter 升级到 Play 服务到 9.4.0
【发布时间】:2016-08-02 07:03:00
【问题描述】:

由于 firebase,我将 play-services 升级到 9.4.0 后,因为它必须为 firebase 添加最新版本 9.0.0 或更高版本,所以我遇到了问题,因为 AutocompletePrediction prediction.getDescription() 现在显示为找不到我的项目,除了 Gradle 更新,我没有改变任何东西,我认为新的播放服务缺少 .getDescription 方法,请帮助我 这是我的新 Gradle ` compile 'com.google.firebase:firebase-core:9.4.0'

compile 'org.osmdroid:osmdroid-android:5.1@aar'
compile 'com.github.MKergall.osmbonuspack:OSMBonusPack:v5.7'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.google.android.gms:play-services-identity:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'

} 应用插件:'com.google.gms.google-services' and this one is my java file where >getDescription is missingpublic PlaceAutocomplete getItem(int position) { 返回 mResultList.get(位置); }

private ArrayList<PlaceAutocomplete> getPredictions(CharSequence constraint) {
    if (mGoogleApiClient != null) {
        Log.i(TAG, "Executing autocomplete query for: " + constraint);
        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);
        // Wait for predictions, set the timeout.
        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);
        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "Error: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            Log.e(TAG, "Error getting place predictions: " + status
                    .toString());
            autocompletePredictions.release();
            return null;
        }

        Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
                + " predictions.");
        Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
        ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
        while (iterator.hasNext()) {
            AutocompletePrediction prediction = iterator.next();
            resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                    prediction.getDescription()));
        }
        // Buffer release
        autocompletePredictions.release();
        return resultList;
    }
    Log.e(TAG, "Google API client is not connected.");
    return null;
}`

【问题讨论】:

    标签: java android google-api google-places-api


    【解决方案1】:

    如 Google 文档所述,不推荐使用 getDescription。

    getDescription() 现在已弃用。 请使用 getFullText()、getPrimaryText() 和/或 getSecondaryText() 检索完整或部分描述, getMatchedSubstrings() 现在已弃用。请使用 getFullText() 更轻松地格式化匹配。 https://developers.google.com/android/guides/releases

    【讨论】:

    • 你是我在调试时见过这些方法中最好的让我尝试一下,希望它们能奏效
    • @haider:你介意在移植到 9.4.0 后分享你的代码吗?我在这方面遇到了很多麻烦。
    • @menawi 使用我上面的代码,只需将这一行 prediction.getDescription() 替换为 prediction.getFullText()
    • 在 getFullText(CharacterStyle) 中作为参数传递的内容
    • @Ritzor 来自 AutocompletePrediction 的 API,“如果您不想突出显示匹配项,您可以传递 null。”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    相关资源
    最近更新 更多