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

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

Introduction

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

Prototype

DistanceMatrixStatus REQUEST_DENIED

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

Click Source Link

Document

The service denied use of the Distance Matrix service by your web page.

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;/* ww w. j a v  a  2s .c o 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) {

            }

        }
    });

}