Example usage for com.google.gwt.maps.client.geocoder HasGeocoderRequest setAddress

List of usage examples for com.google.gwt.maps.client.geocoder HasGeocoderRequest setAddress

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.geocoder HasGeocoderRequest setAddress.

Prototype

public void setAddress(String address);

Source Link

Document

Address.

Usage

From source file:com.google.mobile.trippy.web.client.presenter.CreateNewTripPresenter.java

License:Apache License

/**
 * Creates the trip by providing the location trip using service.
 *///from ww  w  . j a  v a2s  .  co  m
void createTrip(final String location) {
    final HasGeocoderRequest geocoderRequest = geocoderRequestProvider.get();
    geocoderRequest.setAddress(location);
    singletonComponents.getToast().showLoading(singletonComponents.getMessage().toastMsgResolvingName());
    geocoder.geocode(geocoderRequest, new GeocoderCallback() {

        @Override
        public void callback(final List<HasGeocoderResult> responses, final String status) {
            singletonComponents.getToast().hideLoading();

            switch (responses.size()) {
            case 0: // no locations found
                singletonComponents.getToast().showToast(singletonComponents.getMessage().noTripLocations(),
                        STATUS_TIME_MILLIS);
                break;

            case 1: // one location found create trip directly
                final HasGeocoderGeometry geometry = responses.get(0).getGeometry();
                if (geometry.getBounds() != null) {
                    final String address = responses.get(0).getAddressComponents().get(0).getLongName();
                    addTripToDb(location, address, geometry.getBounds());
                } else {
                    singletonComponents.getToast().showToast(singletonComponents.getMessage().noTripLocations(),
                            STATUS_TIME_MILLIS);
                }
                break;

            default: // more than one location found, allow user to choose one
                if (registerSuggestedHandlers(responses)) {
                    display.showPopup();
                } else {
                    singletonComponents.getToast().showToast(singletonComponents.getMessage().noTripLocations(),
                            STATUS_TIME_MILLIS);
                }
                break;
            }
        }
    });
}