Example usage for com.google.gwt.maps.client.services DistanceMatrixStatus UNKNOWN_ERROR

List of usage examples for com.google.gwt.maps.client.services DistanceMatrixStatus UNKNOWN_ERROR

Introduction

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

Prototype

DistanceMatrixStatus UNKNOWN_ERROR

To view the source code for com.google.gwt.maps.client.services DistanceMatrixStatus UNKNOWN_ERROR.

Click Source Link

Document

A Distance Matrix request could not be processed due to a server error.

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;//from w ww. j a  v a2  s  . co m
    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) {

            }

        }
    });

}