Example usage for com.google.gwt.maps.client.services DirectionsRoute getLegs

List of usage examples for com.google.gwt.maps.client.services DirectionsRoute getLegs

Introduction

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

Prototype

public final native JsArray<DirectionsLeg> getLegs() ;

Source Link

Document

An array of DirectionsLegs, each of which contains information about the steps of which it is composed.

Usage

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

License:Apache License

private void updateStatus(DirectionsRoute route, Date departureDateTime) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < route.getLegs().length(); i++) {
        DirectionsLeg leg = route.getLegs().get(i);
        sb.append(leg.getStart_Address()).append(" &rarr; ").append(leg.getEnd_Address());
        sb.append("<br/>");
        Date arrivalDate = null;/*ww  w  .jav a2 s .  c o m*/
        if (leg.getDuration() != null) {
            sb.append(leg.getDuration().getText()).append(" / ");
            arrivalDate = new Date(departureDateTime.getTime() + leg.getDuration().getValue() * 1000);
        }
        sb.append(leg.getDistance().getText());
        sb.append(" (");
        sb.append(departureDateTime.toString());
        if (arrivalDate != null)
            sb.append(" &rarr; ").append(arrivalDate.toString());
        sb.append(")<br/>");
    }
    htmlSummary.setHTML(sb.toString());
}

From source file:net.cbtltd.client.field.RouteField.java

public String getValue() {
    StringBuilder sb = new StringBuilder();
    JsArray<DirectionsRoute> routes = result.getRoutes();
    if (routes == null) {
        sb.append("No directions available");
    } else {/*from   ww w  .j  a  va  2  s .  c o  m*/
        sb.append("Route\n");
        for (int i = 0; i < routes.length(); i++) {
            DirectionsRoute route = routes.get(i);
            sb.append(route.getWarnings());
            JsArray<DirectionsLeg> legs = route.getLegs();
            for (int j = 0; j < routes.length(); j++) {
                DirectionsLeg leg = legs.get(j);
                sb.append(leg.getStart_Address());
                sb.append(" to ");
                sb.append(leg.getEnd_Address());
                sb.append(" ");
                sb.append(leg.getDistance().getText());
                sb.append(" (");
                sb.append(leg.getDuration().getText());
                sb.append(")\n\n");
            }
        }
    }
    return Text.stripHTML(sb.toString());
}

From source file:net.cbtltd.client.field.RouteField.java

/**
 * Gets the HTML table of the route directions.
 * /*  w w  w.j  a va 2s .  c  o  m*/
 * @param all is true if the <pre><html><body>...</body></html></pre> tags are to be included. 
 * @return the HTML table of the route directions.
 */
public String getHTML(boolean all) {
    StringBuilder sb = new StringBuilder();
    if (all) {
        sb.append("<html><body>");
    }
    JsArray<DirectionsRoute> routes = result.getRoutes();
    if (routes == null) {
        sb.append("No directions available");
    }
    for (int i = 0; i < routes.length(); i++) {
        DirectionsRoute route = routes.get(i);
        sb.append(route.getWarnings());
        JsArray<DirectionsLeg> legs = route.getLegs();
        for (int j = 0; j < routes.length(); j++) {
            DirectionsLeg leg = legs.get(j);
            sb.append("<tr>");
            sb.append("<td>");
            sb.append(leg.getStart_Address() + " to " + leg.getEnd_Address());
            sb.append("</td>");
            sb.append("<td>");
            sb.append(leg.getDistance().getText());
            sb.append("</td>");
            sb.append("<td>(");
            sb.append(leg.getDuration().getText());
            sb.append(")</td>");
            sb.append("</tr>");
        }
        sb.append("</table>");
    }
    if (all) {
        sb.append("</body></html>");
    }
    return sb.toString();
}