我正在迁移到新的API,但是由于存在许多错误,因此无法升级到新的API,我偶然发现许多错误,然后还原更改,无法进行更改,基本上是在自动完成的代码中那里的坐标请求
我已经尝试过Google Map迁移指南和GitHub示例代码,但没有成功
private void setGoogleAddress(int position) {
if (mGoogleApiClient != null) {
utils.print("", "Place ID == >"+ predictions.getPlaces().get(position).getPlaceID());
Places.GeoDataApi.getPlaceById(mGoogleApiClient, predictions.getPlaces().get(position).getPlaceID())
.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
if (places.getStatus().isSuccess()) {
Place myPlace = places.get(0);
LatLng queriedLocation = myPlace.getLatLng();
Log.v("Latitude is", "" + queriedLocation.latitude);
Log.v("Longitude is", "" + queriedLocation.longitude);
if (strSelected.equalsIgnoreCase("destination")) {
placePredictions.strDestAddress = myPlace.getAddress().toString();
placePredictions.strDestLatLng = myPlace.getLatLng().toString();
placePredictions.strDestLatitude = myPlace.getLatLng().latitude + "";
placePredictions.strDestLongitude = myPlace.getLatLng().longitude + "";
txtDestination.setText(placePredictions.strDestAddress);
txtDestination.setSelection(0);
} else {
placePredictions.strSourceAddress = myPlace.getAddress().toString();
placePredictions.strSourceLatLng = myPlace.getLatLng().toString();
placePredictions.strSourceLatitude = myPlace.getLatLng().latitude + "";
placePredictions.strSourceLongitude = myPlace.getLatLng().longitude + "";
txtaddressSource.setText(placePredictions.strSourceAddress);
txtaddressSource.setSelection(0);
txtDestination.requestFocus();
mAutoCompleteAdapter = null;
}
}
mAutoCompleteList.setVisibility(View.GONE);
if (txtDestination.getText().toString().length() > 0) {
places.release();
if (strSelected.equalsIgnoreCase("destination")) {
if (!placePredictions.strDestAddress.equalsIgnoreCase(placePredictions.strSourceAddress)) {
setAddress();
} else {
Toast.makeText(thisActivity, "address not so accurate or should not be same!", Toast.LENGTH_SHORT).show();
//utils.showAlert(thisActivity, "address not so accurate or should not be same!");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent();
intent.putExtra("pick_location", "yes");
intent.putExtra("type", strSelected);
setResult(RESULT_OK, intent);
finish();
}
}, 500);
}
}
} else {
txtDestination.requestFocus();
txtDestination.setText("");
imgDestClose.setVisibility(View.GONE);
mAutoCompleteList.setVisibility(View.GONE);
}
}
});
}
}
public String getPlaceAutoCompleteUrl(String input) {
StringBuilder urlString = new StringBuilder();
urlString.append("https://maps.googleapis.com/maps/api/place/autocomplete/json");
urlString.append("?input=");
try {
urlString.append(URLEncoder.encode(input, "utf8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
urlString.append("&location=");
urlString.append(latitude + "," + longitude); // append lat long of current location to show nearby results.
urlString.append("&radius=500&language=en");
urlString.append("&key=" + getResources().getString(R.string.google_map_api));
Log.d("FINAL URL::: ", urlString.toString());
return urlString.toString();
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.build();
}
我只需要进行更改即可与新的com.google.android.libraries.places:places:1.1.0
兼容