Search in sources :

Example 1 with FetchPlaceResponse

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());
            }
        }
    });
}
Also used : FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) PlaceModel(com.hypertrack.live.models.PlaceModel) FetchPlaceResponse(com.google.android.libraries.places.api.net.FetchPlaceResponse) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) ApiException(com.google.android.gms.common.api.ApiException) ApiException(com.google.android.gms.common.api.ApiException)

Example 2 with FetchPlaceResponse

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));
}
Also used : Field(com.google.android.libraries.places.api.model.Place.Field) FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) FetchPlaceResponse(com.google.android.libraries.places.api.net.FetchPlaceResponse)

Aggregations

FetchPlaceRequest (com.google.android.libraries.places.api.net.FetchPlaceRequest)2 FetchPlaceResponse (com.google.android.libraries.places.api.net.FetchPlaceResponse)2 ApiException (com.google.android.gms.common.api.ApiException)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 Field (com.google.android.libraries.places.api.model.Place.Field)1 PlaceModel (com.hypertrack.live.models.PlaceModel)1