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

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

Introduction

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

Prototype

public final void setMap(MapWidget mapWidget) 

Source Link

Document

This method specifies the map on which directions will be rendered.

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);/*  w  ww  .j  a v  a  2 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) {

            }

        }
    });
}