Example usage for com.google.gwt.maps.client.services TransitOptions newInstance

List of usage examples for com.google.gwt.maps.client.services TransitOptions newInstance

Introduction

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

Prototype

public static final TransitOptions newInstance() 

Source Link

Document

Create new TransitOptions to be used within a DirectionRequest.

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);//from  w  w w  . ja  va  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  .  ja  va  2s  . 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());
            }
        }
    });
}