Java Google将api AutocompletePrediction.getDescription()在升级到9.4.0后丢失
由于firebase的原因,我将play services升级到9.4.0之后,因为必须为firebase添加最新版本9.0.0或更高版本,所以我面临自动完成预测的问题。getDescription()现在显示为在我的项目中找不到,除了Gradle更新之外,我没有做任何更改,我认为新的播放服务缺少.getDescription方法,请帮助我 这是我新的Gradle'compile'com.google.firebase:firebase核心:9.4.0'Java Google将api AutocompletePrediction.getDescription()在升级到9.4.0后丢失,java,android,google-api,google-places-api,Java,Android,Google Api,Google Places Api,由于firebase的原因,我将play services升级到9.4.0之后,因为必须为firebase添加最新版本9.0.0或更高版本,所以我面临自动完成预测的问题。getDescription()现在显示为在我的项目中找不到,除了Gradle更新之外,我没有做任何更改,我认为新的播放服务缺少.getDescription方法,请帮助我 这是我新的Gradle'compile'com.google.firebase:firebase核心:9.4.0' compile 'org.osmdroi
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服务”
这是我的java文件,其中缺少>getDescription
public PlaceAutocomplete getItem(int位置){
返回mResultList.get(位置);
}
private ArrayList getPredictions(CharSequence约束){
if(mGoogleApiClient!=null){
Log.i(标记“为“+约束”执行自动完成查询);
Pendingreult结果=
Places.GeoDataApi
.getAutocompletePredictions(mgoogleAppClient,constraint.toString(),
mBounds,mPlaceFilter);
//等待预测,设置超时。
AutocompletePredictionBuffer autocompletePredictions=结果
.等待(60,时间单位秒);
最终状态状态=自动完成预测。getStatus();
如果(!status.issucess()){
Toast.makeText(getContext(),“错误:+status.toString(),
吐司。长度(短)。show();
Log.e(标记“获取位置预测时出错:”+状态
.toString());
autocompletePredictions.release();
返回null;
}
Log.i(标记“querycompleted.Received”+autocompletedpredictions.getCount()
+"预测";;
迭代器迭代器=自动完成预测。迭代器();
ArrayList resultList=新的ArrayList(autocompletePredictions.getCount());
while(iterator.hasNext()){
AutocompletePrediction prediction=iterator.next();
resultList.add(新建PlaceAutocomplete(prediction.getPlaceId()),
prediction.getDescription());
}
//缓冲释放
autocompletePredictions.release();
返回结果列表;
}
e(标记“GoogleAPI客户端未连接”);
返回null;
}`
getDescription不推荐使用,正如Google文档中提到的那样
getDescription()现在已不推荐使用请使用getFullText()、getPrimaryText()和/或getSecondaryText()检索完整或部分描述,
getMatchedSubstrings()现在已不推荐使用。请使用getFullText()更轻松地格式化匹配项。
您是我在调试时见过的最好的方法。让我尝试一下,我希望它们会work@haider:您介意在移植到9.4.0后共享您的代码吗?我在这方面遇到了很多问题。@menawi使用我上面讨论的代码,只需将这一行prediction.getDescription()替换为prediction.getFullText()AutocompletePrediction API中getFullText(CharacterStyle)@Ritzor中作为参数传递的内容,“如果不希望突出显示匹配项,可以传递null。”
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;
}`