我无法迁移我的Android脚本时出现错误,无法解析符号“ Geo_data_api” 这是我的完整代码。
package in.techware.lataxi.activity;
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.enableAutoManage(this, this)
.build();
这怎么了?
答案 0 :(得分:0)
不建议使用您的操作方式您可以从链接Migrating to the New Places SDK Client中看到最新的迁移信息
答案 1 :(得分:0)
Android版Places SDK引入了具有更新功能的全新静态库。 Android版Places SDK的Google Play服务版本(即com.google.android.gms:play-services-places)已于2019年1月29日弃用,并将于2019年7月29日关闭。
您必须迁移到新的Places SDK。
答案 2 :(得分:0)
现在,您无需使用GoogleApiClient类。 代码已弃用,您必须将旧代码迁移到新代码。
我正在发布一种新的方法。
etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 0) {
recycleView.setVisibility(View.VISIBLE);
imgCancel.setVisibility(View.VISIBLE);
getPlaceAutoCompleteUrl(s.toString());
} else {
recycleView.setVisibility(View.GONE);
imgCancel.setVisibility(View.INVISIBLE);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
public void getPlaceAutoCompleteUrl(String input) {
ApiInterface apiInterface =
RetrofitClient.getClient().create(ApiInterface.class);
StringBuilder urlString = new StringBuilder();
urlString.append("json?input=");
try {
urlString.append(URLEncoder.encode(input, "utf8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
urlString.append("&location=");
urlString.append(mylocation.getLatitude() + "," +
mylocation.getLongitude()); // append lat long of current location to show nearby results.
urlString.append("&radius=500");
urlString.append("&sensor=true");
urlString.append("&language=en");
urlString.append("&key=" + getString(R.string.mapKey));
Log.d("Destination", "apiInter URL " + urlString.toString());
Call<GooglePlaceModal> call = apiInterface.getGooglePlaces(urlString.toString());
call.enqueue(new Callback<GooglePlaceModal>() {
@Override
public void onResponse(Call<GooglePlaceModal> call, Response<GooglePlaceModal> response) {
Log.d("Destination", "apiInter response " + response.body().getPredictions().size());
if (response.body()!=null && response.body().getPredictions()!=null &&response.body().getPredictions().size() > 0) {
recycleView.setVisibility(View.VISIBLE);
list = new ArrayList<>();
list = response.body().getPredictions();
GooglePlaceAdapter(this, list, mWidth);
recycleView.setAdapter(placeAdapter);
placeAdapter.notifyDataSetChanged();
}
}
@Override
public void onFailure(Call<GooglePlaceModal> call, Throwable t) {
t.printStackTrace();
}
});
}