use of com.google.android.libraries.places.api.net.FetchPlaceResponse in project hypertrack-live-android by hypertrack.
the class SearchPlacePresenter method selectItem.
public void selectItem(PlaceModel placeModel) {
view.showProgressBar();
if (!placeModel.isRecent) {
state.addPlaceToRecent(placeModel);
}
List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG, Place.Field.ADDRESS);
FetchPlaceRequest request = FetchPlaceRequest.builder(placeModel.placeId, fields).setSessionToken(token).build();
placesClient.fetchPlace(request).addOnSuccessListener(new OnSuccessListener<FetchPlaceResponse>() {
@Override
public void onSuccess(FetchPlaceResponse fetchPlaceResponse) {
view.hideProgressBar();
PlaceModel destination = new PlaceModel();
destination.address = fetchPlaceResponse.getPlace().getAddress();
destination.latLng = fetchPlaceResponse.getPlace().getLatLng();
state.setDestination(destination);
providePlace(destination);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
view.hideProgressBar();
if (e instanceof ApiException) {
ApiException apiException = (ApiException) e;
Log.e(TAG, "Place not found: " + apiException.getStatusCode());
}
}
});
}
use of com.google.android.libraries.places.api.net.FetchPlaceResponse in project android-places-demos by googlemaps.
the class PlaceAndPhotoTestActivity method fetchPlace.
/**
* Fetches the {@link Place} specified via the UI and displays it. May also trigger {@link
* #fetchPhoto(PhotoMetadata)} if set in the UI.
*/
private void fetchPlace() {
responseView.setText(null);
photoView.setImageBitmap(null);
dismissKeyboard(findViewById(R.id.place_id_field));
final boolean isFetchPhotoChecked = isFetchPhotoChecked();
List<Field> placeFields = getPlaceFields();
String customPhotoReference = getCustomPhotoReference();
if (!validateInputs(isFetchPhotoChecked, placeFields, customPhotoReference)) {
return;
}
setLoading(true);
FetchPlaceRequest request = FetchPlaceRequest.newInstance(getPlaceId(), placeFields);
Task<FetchPlaceResponse> placeTask = placesClient.fetchPlace(request);
placeTask.addOnSuccessListener((response) -> {
responseView.setText(StringUtil.stringify(response, isDisplayRawResultsChecked()));
if (isFetchPhotoChecked) {
attemptFetchPhoto(response.getPlace());
}
});
placeTask.addOnFailureListener((exception) -> {
exception.printStackTrace();
responseView.setText(exception.getMessage());
});
placeTask.addOnCompleteListener(response -> setLoading(false));
}
Aggregations