Example usage for com.google.gwt.maps.client.services DirectionsRequest setTransitOptions

List of usage examples for com.google.gwt.maps.client.services DirectionsRequest setTransitOptions

Introduction

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

Prototype

public final native void setTransitOptions(TransitOptions transitOptions) ;

Source Link

Document

Settings that apply only to requests where travelMode is TRANSIT.

Usage

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

License:Apache License

private void drawRandomDirections() {
    /* Compute a direction with random from, to */
    LatLng origin = LatLng.newInstance(Math.random() * (MAX_LAT - MIN_LAT) + MIN_LAT,
            Math.random() * (MAX_LON - MIN_LON) + MIN_LON);
    LatLng destination = LatLng.newInstance(Math.random() * (MAX_LAT - MIN_LAT) + MIN_LAT,
            Math.random() * (MAX_LON - MIN_LON) + MIN_LON);

    DirectionsRequest request = DirectionsRequest.newInstance();
    request.setOrigin(origin);/* w  w  w.j ava 2 s . c  om*/
    request.setDestination(destination);
    request.setTravelMode(TravelMode.TRANSIT);
    TransitOptions transitOptions = TransitOptions.newInstance();
    long departure = System.currentTimeMillis() + Math.round(Math.random() * DELTA_TIME_MS) - DELTA_TIME_MS / 2;
    final Date departureDateTime = new Date(departure);
    transitOptions.setDepartureTime(departureDateTime);
    request.setTransitOptions(transitOptions);
    request.setOptimizeWaypoints(true);

    DirectionsService o = DirectionsService.newInstance();
    o.route(request, new DirectionsResultHandler() {
        public void onCallback(DirectionsResult result, DirectionsStatus status) {
            if (status == DirectionsStatus.OK) {
                directionsDisplay.setDirections(result);
                DirectionsRoute route = result.getRoutes().get(0);
                htmlStatus.setHTML("Request OK");
                updateStatus(route, departureDateTime);
            } else {
                htmlStatus.setHTML("Request error: " + status.value());
            }
        }
    });
}

From source file:eu.vital.maps.client.maps.TransitDirectionsServiceMapWidget.java

License:Apache License

private void drawRandomDirections() {

    /* Compute a direction with random from, to */
    LatLng origin = LatLng.newInstance(Math.random() * (MAX_LAT - MIN_LAT) + MIN_LAT,
            Math.random() * (MAX_LON - MIN_LON) + MIN_LON);
    LatLng destination = LatLng.newInstance(Math.random() * (MAX_LAT - MIN_LAT) + MIN_LAT,
            Math.random() * (MAX_LON - MIN_LON) + MIN_LON);

    DirectionsRequest request = DirectionsRequest.newInstance();
    request.setOrigin(origin);/*from ww  w.j a  v  a  2 s  .  c  om*/
    request.setDestination(destination);
    request.setTravelMode(TravelMode.TRANSIT);
    TransitOptions transitOptions = TransitOptions.newInstance();
    long departure = System.currentTimeMillis() + Math.round(Math.random() * DELTA_TIME_MS) - DELTA_TIME_MS / 2;
    final Date departureDateTime = new Date(departure);
    transitOptions.setDepartureTime(departureDateTime);
    request.setTransitOptions(transitOptions);
    request.setOptimizeWaypoints(true);

    DirectionsService o = DirectionsService.newInstance();
    o.route(request, new DirectionsResultHandler() {
        public void onCallback(DirectionsResult result, DirectionsStatus status) {
            if (status == DirectionsStatus.OK) {
                directionsDisplay.setDirections(result);
                DirectionsRoute route = result.getRoutes().get(0);
                htmlStatus.setHTML("Request OK");
                updateStatus(route, departureDateTime);
            } else {
                htmlStatus.setHTML("Request error: " + status.value());
            }
        }
    });
}