Example usage for com.google.gwt.maps.client.services TravelMode TRANSIT

List of usage examples for com.google.gwt.maps.client.services TravelMode TRANSIT

Introduction

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

Prototype

TravelMode TRANSIT

To view the source code for com.google.gwt.maps.client.services TravelMode TRANSIT.

Click Source Link

Document

Specifies a transit directions request.

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 av a2  s  . com*/
    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);//  ww w .  j a v a2s.  c o  m
    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());
            }
        }
    });
}