Package com.google.maps
Class DirectionsApiRequest
- java.lang.Object
-
- com.google.maps.DirectionsApiRequest
-
- All Implemented Interfaces:
PendingResult<DirectionsResult>
public class DirectionsApiRequest extends java.lang.Object
Request for the Directions API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DirectionsApiRequest.Waypoint
-
Nested classes/interfaces inherited from interface com.google.maps.PendingResult
PendingResult.Callback<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
optimizeWaypoints
protected DirectionsApiRequest.Waypoint[]
waypoints
-
Constructor Summary
Constructors Constructor Description DirectionsApiRequest(GeoApiContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DirectionsApiRequest
alternatives(boolean alternateRoutes)
If set to true, specifies that the Directions service may provide more than one route alternative in the response.DirectionsApiRequest
arrivalTime(java.time.Instant time)
Set the arrival time for a Transit directions request.DirectionsApiRequest
avoid(DirectionsApi.RouteRestriction... restrictions)
Indicates that the calculated route(s) should avoid the indicated features.T
await()
Performs the request synchronously.T
awaitIgnoreError()
Performs the request synchronously, ignoring exceptions while performing the request and errors returned by the server.void
cancel()
Attempts to cancel the request.A
channel(java.lang.String channel)
A channel to pass with the request.A
custom(java.lang.String parameter, java.lang.String value)
Custom parameter.DirectionsApiRequest
departureTime(java.time.Instant time)
Set the departure time for a transit or driving directions request.DirectionsApiRequest
departureTimeNow()
Set the departure time for a transit or driving directions request as the current time.DirectionsApiRequest
destination(LatLng destination)
The destination, as a latitude/longitude location.DirectionsApiRequest
destination(java.lang.String destination)
The address or textual latitude/longitude value from which you wish to calculate directions.DirectionsApiRequest
destinationPlaceId(java.lang.String destinationPlaceId)
The Place ID value from which you wish to calculate directions.A
experienceIds(java.lang.String... experienceIds)
Sets the value for the HTTP header field nameHttpHeaders.X_GOOG_MAPS_EXPERIENCE_ID
.A
header(java.lang.String key, java.lang.String value)
Sets the header namedkey
tovalue
.A
language(java.lang.String language)
The language in which to return results.DirectionsApiRequest
mode(TravelMode mode)
Specifies the mode of transport to use when calculating directions.DirectionsApiRequest
optimizeWaypoints(boolean optimize)
Allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order.DirectionsApiRequest
origin(LatLng origin)
The origin, as a latitude/longitude location.DirectionsApiRequest
origin(java.lang.String origin)
The address or textual latitude/longitude value from which you wish to calculate directions.DirectionsApiRequest
originPlaceId(java.lang.String originPlaceId)
The Place ID value from which you wish to calculate directions.protected A
param(java.lang.String key, int val)
protected A
param(java.lang.String key, com.google.maps.internal.StringJoin.UrlValue val)
protected A
param(java.lang.String key, java.lang.String val)
protected A
paramAddToList(java.lang.String key, com.google.maps.internal.StringJoin.UrlValue val)
protected A
paramAddToList(java.lang.String key, java.lang.String val)
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>
params()
java.lang.String
prefixPlaceId(java.lang.String placeId)
Helper method for prefixing a Place ID, as specified by the API.DirectionsApiRequest
region(java.lang.String region)
void
setCallback(PendingResult.Callback<T> callback)
DirectionsApiRequest
trafficModel(TrafficModel trafficModel)
Specifies the traffic model to use when requesting future driving directions.DirectionsApiRequest
transitMode(TransitMode... transitModes)
Specifies one or more preferred modes of transit.DirectionsApiRequest
transitRoutingPreference(TransitRoutingPreference pref)
Specifies preferences for transit requests.DirectionsApiRequest
units(Unit units)
Specifies the unit system to use when displaying results.protected void
validateRequest()
DirectionsApiRequest
waypoints(DirectionsApiRequest.Waypoint... waypoints)
Specifies a list of waypoints.DirectionsApiRequest
waypoints(LatLng... waypoints)
The list of waypoints as latitude/longitude locations.DirectionsApiRequest
waypoints(java.lang.String... waypoints)
Specifies the list of waypoints as String addresses.DirectionsApiRequest
waypointsFromPlaceIds(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
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 toTRANSIT
you must also specify either adepartureTime
or anarrivalTime
.- Parameters:
mode
- The travel mode to request directions for.- Returns:
- Returns this
DirectionsApiRequest
for 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
objects.- 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 withplace_id:
.- 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.- 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.- 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:
.
-
setCallback
public final void setCallback(PendingResult.Callback<T> callback)
Description copied from interface:PendingResult
Performs the request asynchronously, callingonResult
oronFailure
after the request has been completed.- Specified by:
setCallback
in interfacePendingResult<T>
- Parameters:
callback
- The callback to call on completion.
-
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 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:PendingResult
Performs the request synchronously, ignoring exceptions while performing the request and errors returned by the server.- Specified by:
awaitIgnoreError
in interfacePendingResult<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 interfacePendingResult<T>
-
header
public A header(java.lang.String key, java.lang.String value)
Sets the header namedkey
tovalue
. If this request already has any headers with the same key, the value is replaced.- Parameters:
key
- the header keyvalue
- the header value- Returns:
- this request
-
experienceIds
public A experienceIds(java.lang.String... experienceIds)
Sets the value for the HTTP header field nameHttpHeaders.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.
-
-