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

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

Introduction

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

Prototype

public final native void setDestination(LatLng destination) ;

Source Link

Document

Location of destination.

Usage

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

License:Apache License

private void drawDirectionsWithMidPoint() {
    DirectionsRendererOptions options = DirectionsRendererOptions.newInstance();
    final DirectionsRenderer directionsDisplay = DirectionsRenderer.newInstance(options);
    directionsDisplay.setMap(mapWidget);

    String origin = "Arlington, WA";
    String destination = "Seattle, WA";

    DirectionsRequest request = DirectionsRequest.newInstance();
    request.setOrigin(origin);/*ww w  . j av a 2  s. c  o  m*/
    request.setDestination(destination);
    request.setTravelMode(TravelMode.DRIVING);
    request.setOptimizeWaypoints(true);

    // Stop over
    LatLng stopOverWayPoint = LatLng.newInstance(47.8587, -121.9697);
    DirectionsWaypoint waypoint = DirectionsWaypoint.newInstance();
    waypoint.setStopOver(true);
    waypoint.setLocation(stopOverWayPoint);

    JsArray<DirectionsWaypoint> waypoints = JsArray.createArray().cast();
    waypoints.push(waypoint);
    request.setWaypoints(waypoints);

    DirectionsService o = DirectionsService.newInstance();
    o.route(request, new DirectionsResultHandler() {
        public void onCallback(DirectionsResult result, DirectionsStatus status) {
            if (status == DirectionsStatus.OK) {
                directionsDisplay.setDirections(result);
                getDistance();
            } else if (status == DirectionsStatus.INVALID_REQUEST) {

            } else if (status == DirectionsStatus.MAX_WAYPOINTS_EXCEEDED) {

            } else if (status == DirectionsStatus.NOT_FOUND) {

            } else if (status == DirectionsStatus.OVER_QUERY_LIMIT) {

            } else if (status == DirectionsStatus.REQUEST_DENIED) {

            } else if (status == DirectionsStatus.UNKNOWN_ERROR) {

            } else if (status == DirectionsStatus.ZERO_RESULTS) {

            }

        }
    });
}

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  v  a 2 s .  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());
            }
        }
    });
}

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 a  2s  . co 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());
            }
        }
    });
}

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

public void setValue(String value) {
    String args[] = value.split("-");
    DirectionsRequest rq = DirectionsRequest.newInstance();
    rq.setAvoidHighways(false);/*from   w ww  .  ja  v a 2 s  .  co m*/
    rq.setAvoidTolls(true);
    rq.setOrigin(args[0]);
    rq.setDestination(args[1]);
    if (args.length > 2) {
        rq.setRegion(args[2]);
    }
    rq.setOptimizeWaypoints(true);
    rq.setProvideRouteAlternatives(false);
    rq.setTravelMode(TravelMode.DRIVING);
    rq.setUnitSystem(UnitSystem.METRIC);

    DirectionsService directions = DirectionsService.newInstance();
    directions.route(rq, new DirectionsResultHandler() {
        public void onCallback(DirectionsResult rs, DirectionsStatus status) {
            setResult(rs);
        }
    });
}