Example usage for com.google.gwt.maps.client.services Distance getText

List of usage examples for com.google.gwt.maps.client.services Distance getText

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.services Distance getText.

Prototype

public final native String getText() ;

Source Link

Document

A string representation of the distance value, using the UnitSystem specified in the request.

Usage

From source file:com.google.gwt.maps.testing.client.maps.DirectionsServiceMapWidget.java

License:Apache License

private void getDistance() {
    String origin = "Arlington, WA";
    String destination = "Seattle, WA";

    String[] ao = new String[1];
    ao[0] = origin;/* w  w  w . jav  a2s . com*/
    JsArrayString origins = ArrayHelper.toJsArrayString(ao);

    String[] ad = new String[1];
    ad[0] = destination;
    JsArrayString destinations = ArrayHelper.toJsArrayString(ad);

    DistanceMatrixRequest request = DistanceMatrixRequest.newInstance();
    request.setOrigins(origins);
    request.setDestinations(destinations);
    request.setTravelMode(TravelMode.DRIVING);

    DistanceMatrixService o = DistanceMatrixService.newInstance();
    o.getDistanceMatrix(request, new DistanceMatrixRequestHandler() {
        public void onCallback(DistanceMatrixResponse response, DistanceMatrixStatus status) {
            GWT.log("status=" + status.value());

            if (status == DistanceMatrixStatus.INVALID_REQUEST) {

            } else if (status == DistanceMatrixStatus.MAX_DIMENSIONS_EXCEEDED) {

            } else if (status == DistanceMatrixStatus.MAX_ELEMENTS_EXCEEDED) {

            } else if (status == DistanceMatrixStatus.OK) {

                @SuppressWarnings("unused")
                JsArrayString dest = response.getDestinationAddresses();
                @SuppressWarnings("unused")
                JsArrayString org = response.getOriginAddresses();
                JsArray<DistanceMatrixResponseRow> rows = response.getRows();

                GWT.log("rows.length=" + rows.length());
                DistanceMatrixResponseRow d = rows.get(0);
                JsArray<DistanceMatrixResponseElement> elements = d.getElements();
                for (int i = 0; i < elements.length(); i++) {
                    DistanceMatrixResponseElement e = elements.get(i);
                    Distance distance = e.getDistance();
                    Duration duration = e.getDuration();

                    @SuppressWarnings("unused")
                    DistanceMatrixElementStatus st = e.getStatus();
                    GWT.log("distance=" + distance.getText() + " value=" + distance.getValue());
                    GWT.log("duration=" + duration.getText() + " value=" + duration.getValue());

                    String html = "&nbsp;&nbsp;Distance=" + distance.getText() + " Duration="
                            + duration.getText() + " ";
                    htmlDistanceMatrixService.setHTML(html);
                }

            } else if (status == DistanceMatrixStatus.OVER_QUERY_LIMIT) {

            } else if (status == DistanceMatrixStatus.REQUEST_DENIED) {

            } else if (status == DistanceMatrixStatus.UNKNOWN_ERROR) {

            }

        }
    });

}