Class DirectionsApiRequest

  • All Implemented Interfaces:
    PendingResult<DirectionsResult>

    public class DirectionsApiRequest
    extends java.lang.Object
    Request for the Directions API.
    • Constructor Detail

      • DirectionsApiRequest

        public DirectionsApiRequest​(GeoApiContext context)
    • Method Detail

      • validateRequest

        protected void validateRequest()
      • origin

        public DirectionsApiRequest origin​(java.lang.String origin)
        The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a location, the Directions service will geocode the location and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values.
        Parameters:
        origin - The starting location for the Directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • destination

        public DirectionsApiRequest destination​(java.lang.String destination)
        The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a location, the Directions service will geocode the location and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values.
        Parameters:
        destination - The ending location for the Directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • originPlaceId

        public DirectionsApiRequest originPlaceId​(java.lang.String originPlaceId)
        The Place ID value from which you wish to calculate directions.
        Parameters:
        originPlaceId - The starting location Place ID for the Directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • destinationPlaceId

        public DirectionsApiRequest destinationPlaceId​(java.lang.String destinationPlaceId)
        The Place ID value from which you wish to calculate directions.
        Parameters:
        destinationPlaceId - The ending location Place ID for the Directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • origin

        public DirectionsApiRequest origin​(LatLng origin)
        The origin, as a latitude/longitude location.
        Parameters:
        origin - The starting location for the Directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • destination

        public DirectionsApiRequest destination​(LatLng destination)
        The destination, as a latitude/longitude location.
        Parameters:
        destination - The ending location for the Directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • mode

        public DirectionsApiRequest mode​(TravelMode mode)
        Specifies the mode of transport to use when calculating directions. The mode defaults to driving if left unspecified. If you set the mode to TRANSIT you must also specify either a departureTime or an arrivalTime.
        Parameters:
        mode - The travel mode to request directions for.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • units

        public DirectionsApiRequest units​(Unit units)
        Specifies the unit system to use when displaying results.
        Parameters:
        units - The preferred units for displaying distances.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • region

        public DirectionsApiRequest region​(java.lang.String region)
        Parameters:
        region - The region code, specified as a ccTLD ("top-level domain") two-character value.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • arrivalTime

        public DirectionsApiRequest arrivalTime​(java.time.Instant time)
        Set the arrival time for a Transit directions request.
        Parameters:
        time - The arrival time to calculate directions for.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • departureTime

        public DirectionsApiRequest departureTime​(java.time.Instant time)
        Set the departure time for a transit or driving directions request. If both departure time and traffic model are not provided, then "now" is assumed. If traffic model is supplied, then departure time must be specified. Duration in traffic will only be returned if the departure time is specified.
        Parameters:
        time - The departure time to calculate directions for.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • departureTimeNow

        public DirectionsApiRequest departureTimeNow()
        Set the departure time for a transit or driving directions request as the current time. If traffic model is supplied, then departure time must be specified. Duration in traffic will only be returned if the departure time is specified.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • waypoints

        public DirectionsApiRequest waypoints​(DirectionsApiRequest.Waypoint... waypoints)
        Specifies a list of waypoints. Waypoints alter a route by routing it through the specified location(s). A waypoint is specified as either a latitude/longitude coordinate or as an address which will be geocoded. Waypoints are only supported for driving, walking and bicycling directions.

        For more information on waypoints, see Using Waypoints in Routes.

        Parameters:
        waypoints - The waypoints to add to this directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • waypoints

        public DirectionsApiRequest waypoints​(java.lang.String... waypoints)
        Specifies the list of waypoints as String addresses. If any of the Strings are Place IDs, you must prefix them with place_id:.

        See prefixPlaceId(String).

        See waypoints(Waypoint...).

        Parameters:
        waypoints - The waypoints to add to this directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • waypointsFromPlaceIds

        public DirectionsApiRequest waypointsFromPlaceIds​(java.lang.String... waypoints)
        Specifies the list of waypoints as Plade ID Strings, prefixing them as required by the API.

        See prefixPlaceId(String).

        See waypoints(Waypoint...).

        Parameters:
        waypoints - The waypoints to add to this directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • waypoints

        public DirectionsApiRequest waypoints​(LatLng... waypoints)
        The list of waypoints as latitude/longitude locations.

        See waypoints(Waypoint...).

        Parameters:
        waypoints - The waypoints to add to this directions request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • optimizeWaypoints

        public DirectionsApiRequest optimizeWaypoints​(boolean optimize)
        Allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order.
        Parameters:
        optimize - Whether to optimize waypoints.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • alternatives

        public DirectionsApiRequest alternatives​(boolean alternateRoutes)
        If set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server.
        Parameters:
        alternateRoutes - whether to return alternate routes.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • transitMode

        public DirectionsApiRequest transitMode​(TransitMode... transitModes)
        Specifies one or more preferred modes of transit. This parameter may only be specified for requests where the mode is transit.
        Parameters:
        transitModes - The preferred transit modes.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • transitRoutingPreference

        public DirectionsApiRequest transitRoutingPreference​(TransitRoutingPreference pref)
        Specifies preferences for transit requests. Using this parameter, you can bias the options returned, rather than accepting the default best route chosen by the API.
        Parameters:
        pref - The transit routing preferences for this request.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • trafficModel

        public DirectionsApiRequest trafficModel​(TrafficModel trafficModel)
        Specifies the traffic model to use when requesting future driving directions. Once set, you must specify a departure time.
        Parameters:
        trafficModel - The traffic model for estimating driving time.
        Returns:
        Returns this DirectionsApiRequest for call chaining.
      • prefixPlaceId

        public java.lang.String prefixPlaceId​(java.lang.String placeId)
        Helper method for prefixing a Place ID, as specified by the API.
        Parameters:
        placeId - The Place ID to be prefixed.
        Returns:
        Returns the Place ID prefixed with place_id:.
      • await

        public final T await()
                      throws ApiException,
                             java.lang.InterruptedException,
                             java.io.IOException
        Description copied from interface: PendingResult
        Performs the request synchronously.
        Specified by:
        await in interface PendingResult<T>
        Returns:
        The result.
        Throws:
        ApiException - Thrown if the API Returned result is an error.
        java.lang.InterruptedException - Thrown when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted.
        java.io.IOException - Thrown when an I/O exception of some sort has occurred.
      • awaitIgnoreError

        public final T awaitIgnoreError()
        Description copied from interface: PendingResult
        Performs the request synchronously, ignoring exceptions while performing the request and errors returned by the server.
        Specified by:
        awaitIgnoreError in interface PendingResult<T>
        Returns:
        The result, or null if there was any error or exception ignored.
      • cancel

        public final void cancel()
        Description copied from interface: PendingResult
        Attempts to cancel the request.
        Specified by:
        cancel in interface PendingResult<T>
      • header

        public A header​(java.lang.String key,
                        java.lang.String value)
        Sets the header named key to value. If this request already has any headers with the same key, the value is replaced.
        Parameters:
        key - the header key
        value - the header value
        Returns:
        this request
      • experienceIds

        public A experienceIds​(java.lang.String... experienceIds)
        Sets the value for the HTTP header field name HttpHeaders.X_GOOG_MAPS_EXPERIENCE_ID. Passing null to this method will unset the experienceId header field.
        Parameters:
        experienceIds - The experience IDs
      • param

        protected A param​(java.lang.String key,
                          java.lang.String val)
      • param

        protected A param​(java.lang.String key,
                          int val)
      • param

        protected A param​(java.lang.String key,
                          com.google.maps.internal.StringJoin.UrlValue val)
      • paramAddToList

        protected A paramAddToList​(java.lang.String key,
                                   java.lang.String val)
      • paramAddToList

        protected A paramAddToList​(java.lang.String key,
                                   com.google.maps.internal.StringJoin.UrlValue val)
      • params

        protected java.util.Map<java.lang.String,​java.util.List<java.lang.String>> params()
      • language

        public final A language​(java.lang.String language)
        The language in which to return results. Note that we often update supported languages so this list may not be exhaustive.
        Parameters:
        language - The language code, e.g. "en-AU" or "es".
        Returns:
        Returns the request for call chaining.
        See Also:
        List of supported domain languages
      • channel

        public A channel​(java.lang.String channel)
        A channel to pass with the request. channel is used by Google Maps API for Work users to be able to track usage across different applications with the same clientID. See Premium Plan Usage Rates and Limits.
        Parameters:
        channel - String to pass with the request for analytics.
        Returns:
        Returns the request for call chaining.
      • custom

        public A custom​(java.lang.String parameter,
                        java.lang.String value)
        Custom parameter. For advanced usage only.
        Parameters:
        parameter - The name of the custom parameter.
        value - The value of the custom parameter.
        Returns:
        Returns the request for call chaining.