Example usage for com.google.gwt.maps.client.services DirectionsRenderer setDirections

List of usage examples for com.google.gwt.maps.client.services DirectionsRenderer setDirections

Introduction

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

Prototype

public final native void setDirections(DirectionsResult directions) ;

Source Link

Document

Set the renderer to use the result from the DirectionsService.

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);//from w  ww . ja  va2 s  .c  om
    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) {

            }

        }
    });
}