Package com.google.maps
Class DirectionsApiRequest
- java.lang.Object
-
- com.google.maps.DirectionsApiRequest
-
- All Implemented Interfaces:
PendingResult<DirectionsResult>
public class DirectionsApiRequest extends java.lang.ObjectRequest for the Directions API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDirectionsApiRequest.Waypoint-
Nested classes/interfaces inherited from interface com.google.maps.PendingResult
PendingResult.Callback<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanoptimizeWaypointsprotected DirectionsApiRequest.Waypoint[]waypoints
-
Constructor Summary
Constructors Constructor Description DirectionsApiRequest(GeoApiContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DirectionsApiRequestalternatives(boolean alternateRoutes)If set to true, specifies that the Directions service may provide more than one route alternative in the response.DirectionsApiRequestarrivalTime(java.time.Instant time)Set the arrival time for a Transit directions request.DirectionsApiRequestavoid(DirectionsApi.RouteRestriction... restrictions)Indicates that the calculated route(s) should avoid the indicated features.Tawait()Performs the request synchronously.TawaitIgnoreError()Performs the request synchronously, ignoring exceptions while performing the request and errors returned by the server.voidcancel()Attempts to cancel the request.Achannel(java.lang.String channel)A channel to pass with the request.Acustom(java.lang.String parameter, java.lang.String value)Custom parameter.DirectionsApiRequestdepartureTime(java.time.Instant time)Set the departure time for a transit or driving directions request.DirectionsApiRequestdepartureTimeNow()Set the departure time for a transit or driving directions request as the current time.DirectionsApiRequestdestination(LatLng destination)The destination, as a latitude/longitude location.DirectionsApiRequestdestination(java.lang.String destination)The address or textual latitude/longitude value from which you wish to calculate directions.DirectionsApiRequestdestinationPlaceId(java.lang.String destinationPlaceId)The Place ID value from which you wish to calculate directions.Alanguage(java.lang.String language)The language in which to return results.DirectionsApiRequestmode(TravelMode mode)Specifies the mode of transport to use when calculating directions.DirectionsApiRequestoptimizeWaypoints(boolean optimize)Allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order.DirectionsApiRequestorigin(LatLng origin)The origin, as a latitude/longitude location.DirectionsApiRequestorigin(java.lang.String origin)The address or textual latitude/longitude value from which you wish to calculate directions.DirectionsApiRequestoriginPlaceId(java.lang.String originPlaceId)The Place ID value from which you wish to calculate directions.protected Aparam(java.lang.String key, int val)protected Aparam(java.lang.String key, com.google.maps.internal.StringJoin.UrlValue val)protected Aparam(java.lang.String key, java.lang.String val)protected AparamAddToList(java.lang.String key, com.google.maps.internal.StringJoin.UrlValue val)protected AparamAddToList(java.lang.String key, java.lang.String val)protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>params()java.lang.StringprefixPlaceId(java.lang.String placeId)Helper method for prefixing a Place ID, as specified by the API.DirectionsApiRequestregion(java.lang.String region)voidsetCallback(PendingResult.Callback<T> callback)DirectionsApiRequesttrafficModel(TrafficModel trafficModel)Specifies the traffic model to use when requesting future driving directions.DirectionsApiRequesttransitMode(TransitMode... transitModes)Specifies one or more preferred modes of transit.DirectionsApiRequesttransitRoutingPreference(TransitRoutingPreference pref)Specifies preferences for transit requests.DirectionsApiRequestunits(Unit units)Specifies the unit system to use when displaying results.protected voidvalidateRequest()DirectionsApiRequestwaypoints(DirectionsApiRequest.Waypoint... waypoints)Specifies a list of waypoints.DirectionsApiRequestwaypoints(LatLng... waypoints)The list of waypoints as latitude/longitude locations.DirectionsApiRequestwaypoints(java.lang.String... waypoints)Specifies the list of waypoints as String addresses.DirectionsApiRequestwaypointsFromPlaceIds(java.lang.String... waypoints)Specifies the list of waypoints as Plade ID Strings, prefixing them as required by the API.
-
-
-
Field Detail
-
optimizeWaypoints
protected boolean optimizeWaypoints
-
waypoints
protected DirectionsApiRequest.Waypoint[] waypoints
-
-
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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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 toTRANSITyou must also specify either adepartureTimeor anarrivalTime.- Parameters:
mode- The travel mode to request directions for.- Returns:
- Returns this
DirectionsApiRequestfor call chaining.
-
avoid
public DirectionsApiRequest avoid(DirectionsApi.RouteRestriction... restrictions)
Indicates that the calculated route(s) should avoid the indicated features.- Parameters:
restrictions- one or more ofDirectionsApi.RouteRestriction.TOLLS,DirectionsApi.RouteRestriction.HIGHWAYS,DirectionsApi.RouteRestriction.FERRIES- Returns:
- Returns this
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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 withplace_id:.- Parameters:
waypoints- The waypoints to add to this directions request.- Returns:
- Returns this
DirectionsApiRequestfor 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.- Parameters:
waypoints- The waypoints to add to this directions request.- Returns:
- Returns this
DirectionsApiRequestfor call chaining.
-
waypoints
public DirectionsApiRequest waypoints(LatLng... waypoints)
The list of waypoints as latitude/longitude locations.- Parameters:
waypoints- The waypoints to add to this directions request.- Returns:
- Returns this
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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
DirectionsApiRequestfor 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:.
-
setCallback
public final void setCallback(PendingResult.Callback<T> callback)
Description copied from interface:PendingResultPerforms the request asynchronously, callingonResultoronFailureafter the request has been completed.- Specified by:
setCallbackin interfacePendingResult<T>- Parameters:
callback- The callback to call on completion.
-
await
public final T await() throws ApiException, java.lang.InterruptedException, java.io.IOExceptionDescription copied from interface:PendingResultPerforms the request synchronously.- Specified by:
awaitin interfacePendingResult<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:PendingResultPerforms the request synchronously, ignoring exceptions while performing the request and errors returned by the server.- Specified by:
awaitIgnoreErrorin interfacePendingResult<T>- Returns:
- The result, or null if there was any error or exception ignored.
-
cancel
public final void cancel()
Description copied from interface:PendingResultAttempts to cancel the request.- Specified by:
cancelin interfacePendingResult<T>
-
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.
-
-