[−][src]Struct google_maps::distance_matrix::request::Request
Look at this Request
struct for documentation on how to build your
Distance Matrix API query. The methods implemented for this struct are
what's used to build your request.
Methods
impl<'a> Request<'a>
[src]
pub fn build(&mut self) -> Result<&'a mut Request, Error>
[src]
Builds the query string for the Google Maps Directions API based on the input provided by the client.
Arguments:
This method accepts no arguments.
impl<'a> Request<'a>
[src]
pub fn execute(&'a mut self) -> Result<Response, Error>
[src]
Executes the query you've built.
Description:
My adventures in Rust became messy so I had to make this method. It
wraps the .validate()?.build()?.get()?
chain needed at the end of the
builder pattern.
Arguments:
This method accepts no arguments.
impl<'a> Request<'a>
[src]
pub fn get(&self) -> Result<Response, Error>
[src]
Performs the HTTP get request and returns the response to the caller.
Arguments:
This method accepts no arguments.
impl<'a> Request<'a>
[src]
pub fn new(
client_settings: &mut ClientSettings,
origins: Vec<Waypoint>,
destinations: Vec<Waypoint>
) -> Request
[src]
client_settings: &mut ClientSettings,
origins: Vec<Waypoint>,
destinations: Vec<Waypoint>
) -> Request
impl<'a> Request<'a>
[src]
pub fn validate(&mut self) -> Result<&'a mut Request, Error>
[src]
Ensures the built query is valid. This function checks the combination of parameters to ensure that they make sense together and that Google Maps Directions API will accept them - i.e. it will not allow both a arrival time and departure time in the same query. This function does not check parameter values for validity - i.e. it will not ensure Polylines or Place ID's are valid and well-formed.
Arguments:
This method accepts no arguments.
impl<'a> Request<'a>
[src]
pub fn with_arrival_time(
&'a mut self,
arrival_time: PrimitiveDateTime
) -> &'a mut Request
[src]
&'a mut self,
arrival_time: PrimitiveDateTime
) -> &'a mut Request
Specifies the desired arrival time.
Arguments:
arrival_time
‧ The time the passenger should arrive at their final destination by.
Description:
Specifies the desired time of arrival for transit distances. You can
use either the .with_departure_time()
or the .with_arrival_time()
method, but not both together.
Example:
- Arriving by January 1, 2019 at 12:00:00 AM:
.with_arrival_time(PrimitiveDateTime::new( PrimitiveDateTime::new(Date::try_from_ymd(2019, 1, 1).unwrap(), Time::midnight() ))
impl<'a> Request<'a>
[src]
pub fn with_departure_time(
&'a mut self,
departure_time: DepartureTime
) -> &'a mut Request
[src]
&'a mut self,
departure_time: DepartureTime
) -> &'a mut Request
Specifies the desired departure time.
Arguments:
departure_time
‧ The soonest time the passenger intends to depart. May be "now" or a specified time.
Description
Specifies the desired time of departure. Alternatively, you can specify a value of now, which sets the departure time to the current time (correct to the nearest second). The departure time may be specified in two cases:
-
For requests where the travel mode is transit: You can optionally use one of
.with_departure_time()
or.with_arrival_time()
methods. If neither time is specified, the departure time defaults to now (that is, the departure time defaults to the current time). -
For requests where the travel mode is driving: You can specify the departure_time to receive a route and trip duration (response field:
duration_in_traffic
) that take traffic conditions into account. This option is only available if the request contains a valid API key, or a valid Google Maps Platform Premium Plan client ID and signature. The departure time must be set to the current time or some time in the future. It cannot be in the past. -
Note: If departure time is not specified, choice of route and duration are based on road network and average time-independent traffic conditions. Results for a given request may vary over time due to changes in the road network, updated average traffic conditions, and the distributed nature of the service. Results may also vary between nearly-equivalent routes at any time or frequency.
Examples:
- Departing now:
.with_departure_time(DepartureTime::Now)
- Departing on Tuesday February 22, 2022 at 1:00:00 PM:
.with_departure_time(DepartureTime::At(PrimitiveDateTime::new( Date::try_from_ymd(2022, 2, 22).unwrap(), Time::try_from_hms(13, 00, 0).unwrap(), )))
- Departing on Tuesday January 1, 2030 at 12:30:00 PM:
.with_departure_time(DepartureTime::At(PrimitiveDateTime::new( Date::try_from_ymd(2030, 1, 1).unwrap(), Time::try_from_hms(12, 30, 0).unwrap(), )))
impl<'a> Request<'a>
[src]
pub fn with_language(&'a mut self, language: Language) -> &'a mut Request
[src]
Specify the language in which to return results.
Arguments:
language
‧ The language that Google's response should be presented in.
Description:
-
See the list of supported languages. Google often updates the supported languages, so this list may not be exhaustive.
-
If
language
is not supplied, the API attempts to use the preferred language as specified in theAccept-Language
header, or the native language of the domain from which the request is sent. -
The API does its best to provide a street address that is readable for both the user and locals. To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user if necessary, observing the preferred language. All other addresses are returned in the preferred language. Address components are all returned in the same language, which is chosen from the first component.
-
If a name is not available in the preferred language, the API uses the closest match.
-
The preferred language has a small influence on the set of results that the API chooses to return, and the order in which they are returned. The geocoder interprets abbreviations differently depending on language, such as the abbreviations for street types, or synonyms that may be valid in one language but not in another. For example, utca and tér are synonyms for street in Hungarian.
Example:
- Force language to French:
.with_language(Language::French)
impl<'a> Request<'a>
[src]
pub fn with_region(&'a mut self, region: Region) -> &'a mut Request
[src]
Specifies the region bias. There is a London in Canada and there is a London in England. By biasing the region, you help the directions service choose the London you intended.
Arguments
region
‧ A country to bias your geocoding results to.
Description
You can set the Directions service to return results from a specific
region by using the region
parameter. You may utilize any domain in
which the main Google Maps application has launched driving directions.
For example, a directions request for "Toledo" to "Madrid" returns
appropriate results when region
is set to Region::Spain
and "Toledo"
is then interpreted as the Spanish city. A directions request for
"Toledo" to "Madrid" sent without a region
parameter does not return
results, because "Toledo" is interpreted as the city in Ohio and not
Spain.
Example:
- Bias region to Canada:
.with_region(Region::Canada)
impl<'a> Request<'a>
[src]
pub fn with_restriction(&'a mut self, restriction: Avoid) -> &'a mut Request
[src]
Specify a feature that routes should avoid.
Arguments
restrictions
‧ A Vec containing a list of features that should be avoided when possible when calculating the route, such as ferries, highways, indoor steps, and/or tolls.
Description
Indicates that the calculated route(s) should avoid the indicated features. This parameter supports the following arguments:
-
Avoid::Tolls
indicates that the calculated route should avoid toll roads/bridges. -
Avoid::Highways
indicates that the calculated route should avoid highways. -
Avoid::Ferries
indicates that the calculated route should avoid ferries. -
Avoid::Indoor
indicates that the calculated route should avoid indoor steps for walking and transit directions. Only requests that include an API key or a Google Maps Platform Premium Plan client ID will receive indoor steps by default.
Directions may be calculated that adhere to certain restrictions. Restrictions are indicated by use of the avoid parameter, and an argument to that parameter indicating the restriction to avoid.
It's possible to request a route that avoids any combination of tolls, highways and ferries by passing both restrictions.
Note: the addition of restrictions does not preclude routes that include the restricted feature; it simply biases the result to more favorable routes.
Examples:
- Only avoid highways:
.with_restriction(Avoid::Highways)
- Multiple restrictions may be stacked together. This example avoids tolls and ferries:
.with_restriction(Avoid::Tolls) .with_restriction(Avoid::Ferries)
pub fn with_restrictions(
&'a mut self,
restrictions_slice: &[Avoid]
) -> &'a mut Request
[src]
&'a mut self,
restrictions_slice: &[Avoid]
) -> &'a mut Request
Specify features that routes should avoid.
Example:
- Alternatively, multiple restrictions may be passed in a single method call by passing a Vec. This example avoids tolls and ferries:
.with_restrictions(vec![ Avoid::Tolls, Avoid::Ferries, ])
impl<'a> Request<'a>
[src]
pub fn with_traffic_model(
&'a mut self,
traffic_model: TrafficModel
) -> &'a mut Request
[src]
&'a mut self,
traffic_model: TrafficModel
) -> &'a mut Request
Specifies the assumptions to use when calculating time in traffic.
Arguments
traffic_model
‧ Which traffic model the directions service should use when calculating the route and duration in traffic - best guess, optimistic, or pessimistic?
Description
Specifies the assumptions to use when calculating time in traffic. This
setting affects the value returned in the duration_in_traffic
field in
the response, which contains the predicted time in traffic based on
historical averages. The traffic_model parameter may only be specified
for driving directions where the request includes a departure_time
,
and only if the request includes an API key or a Google Maps Platform
Premium Plan client ID. The available values for this parameter are:
-
TrafficModel::BestGuess
(default) indicates that the returnedduration_in_traffic
should be the best estimate of travel time given what is known about both historical traffic conditions and live traffic. Live traffic becomes more important the closer the departure_time is to now. -
TrafficModel::Pessimistic
indicates that the returnedduration_in_traffic
should be longer than the actual travel time on most days, though occasional days with particularly bad traffic conditions may exceed this value. -
TrafficModel::Optimistic
indicates that the returnedduration_in_traffic
should be shorter than the actual travel time on most days, though occasional days with particularly good traffic conditions may be faster than this value.
The default value of BestGuess
will give the most useful predictions
for the vast majority of use cases. It is possible the BestGuess
travel time prediction may be shorter than Optimistic
, or
alternatively, longer than Pessimistic
, due to the way the
BestGuess
prediction model integrates live traffic information.
Example:
- Set traffic model to pessimistic:
.with_traffic_model(TrafficModel::Pessimistic)
impl<'a> Request<'a>
[src]
pub fn with_transit_mode(
&'a mut self,
transit_mode: TransitMode
) -> &'a mut Request
[src]
&'a mut self,
transit_mode: TransitMode
) -> &'a mut Request
Specify the preferred mode of transit.
Arguments
transit_modes
‧ The preference of the transit rider; what mode of transit should the directions service prioritize? Bus, Subway, Train, Tram, or Rail?
Description
Specifies one or more preferred modes of transit. This parameter may only be specified for transit directions, and only if the request includes an API key or a Google Maps Platform Premium Plan client ID. The parameter supports the following arguments:
-
TransitMode::Bus
indicates that the calculated route should prefer travel by bus. -
TransitMode::Subway
indicates that the calculated route should prefer travel by subway. -
TransitMode::Train
indicates that the calculated route should prefer travel by train. -
TransitMode::Tram
indicates that the calculated route should prefer travel by tram and light rail. -
TransitMode::Rail
indicates that the calculated route should prefer travel by train, tram, light rail, and subway. This is equivalent toTransitMode::Train|Tram|Subway
.
Examples:
- Set preferred transit mode to rail:
.with_transit_mode(TransitMode::Rail)
- Multiple modes may be stacked together. This example sets preferred transit modes to bus and subway:
.with_transit_mode(TransitMode::Bus) .with_transit_mode(TransitMode::Subway)
pub fn with_transit_modes(
&'a mut self,
transit_modes_slice: &[TransitMode]
) -> &'a mut Request
[src]
&'a mut self,
transit_modes_slice: &[TransitMode]
) -> &'a mut Request
Specifies preferred modes of transit.
Example:
- Alternatively, multiple transit modes may be passed in a single method call by passing a Vec. This example sets preferred transit modes to bus and subway:
.with_transit_modes(vec![ TransitMode::Bus, TransitMode::Subway, ])
impl<'a> Request<'a>
[src]
pub fn with_transit_route_preference(
&'a mut self,
transit_route_preference: TransitRoutePreference
) -> &'a mut Request
[src]
&'a mut self,
transit_route_preference: TransitRoutePreference
) -> &'a mut Request
Specifies the preference for transit routes.
Arguments
transit_route_preference
‧ The preference of the transit rider; should the directions service try to reduce the amount of walking to reach the destination, or reduce the number of bus transfers?
Description
Specifies preferences for transit routes. Using this parameter, you can bias the options returned, rather than accepting the default best route chosen by the API. This parameter may only be specified for transit directions, and only if the request includes an API key or a Google Maps Platform Premium Plan client ID. The parameter supports the following arguments:
-
TransitRoutePreference::LessWalking
indicates that the calculated route should prefer limited amounts of walking. -
TransitRoutePreference::FewerTransfers
indicates that the calculated route should prefer a limited number of transfers.
Example:
- Set transit route preference to fewer transfers:
.with_transit_route_preference(TransitRoutePreference::FewerTransfers)
impl<'a> Request<'a>
[src]
pub fn with_travel_mode(
&'a mut self,
travel_mode: TravelMode
) -> &'a mut Request
[src]
&'a mut self,
travel_mode: TravelMode
) -> &'a mut Request
Specify the mode of transportation.
Arguments
travel_mode
‧ The mode of transportation that distance matrix should be calculated for. For example, transit distances or car driving distances.
Description
For the calculation of distances, you may specify the transportation mode to use. By default, distances are calculated for driving mode.
-
TravelMode::Driving
(default) indicates distance calculation using the road network. -
TravelMode::Walking
requests distance calculation for walking via pedestrian paths & sidewalks (where available). -
TravelMode::Bicycling
requests distance calculation for bicycling via bicycle paths & preferred streets (where available). -
TravelMode::Transit
requests distance calculation via public transit routes (where available). If you set the travel mode toTravelMode::Transit
, you can optionally use eitherwith_departure_time()
orwith_arrival_time()
methods. If neither time is specified, the departure time defaults to now (that is, the departure time defaults to the current time). You can also optionally usewith_transit_mode()
and/orwith_transit_route_preference()
methods.
Note: Both walking and bicycling routes may sometimes not include
clear pedestrian or bicycling paths, so these responses will return
warnings
in the returned result which you must display to the user.
Example:
- Set travel mode to transit:
.with_travel_mode(TravelMode::Transit)
impl<'a> Request<'a>
[src]
pub fn with_unit_system(
&'a mut self,
unit_system: UnitSystem
) -> &'a mut Request
[src]
&'a mut self,
unit_system: UnitSystem
) -> &'a mut Request
Specifies the unit system to use when displaying results.
Arguments
unit_system
‧ The measurement system the distance matrix service should supply in the response, imperial or metric?
Description
Directions results contain text
within distance
fields that may be
displayed to the user to indicate the distance of a particular "step" of
the route. By default, this text uses the unit system of the origin's
country or region.
For example, a route from "Chicago, IL" to "Toronto, ONT" will display
results in miles, while the reverse route will display results in
kilometers. You may override this unit system by setting one explicitly
within the request's unit_system
parameter, passing one of the
following values:
-
UnitSystem::Metric
specifies usage of the metric system. Textual distances are returned using kilometers and meters. -
UnitSystem::Imperial
specifies usage of the Imperial (English) system. Textual distances are returned using miles and feet.
Note: this unit system setting only affects the text
displayed
within distance
fields. The distance
fields also contain values
which are always expressed in meters.
Example:
- Force unit system to Metric:
.with_unit_system(UnitSystem::Metric)
Trait Implementations
impl<'a> Debug for Request<'a>
[src]
impl<'a> PartialEq<Request<'a>> for Request<'a>
[src]
impl<'a> PartialOrd<Request<'a>> for Request<'a>
[src]
fn partial_cmp(&self, other: &Request<'a>) -> Option<Ordering>
[src]
fn lt(&self, other: &Request<'a>) -> bool
[src]
fn le(&self, other: &Request<'a>) -> bool
[src]
fn gt(&self, other: &Request<'a>) -> bool
[src]
fn ge(&self, other: &Request<'a>) -> bool
[src]
impl<'a> StructuralPartialEq for Request<'a>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for Request<'a>
impl<'a> Send for Request<'a>
impl<'a> Sync for Request<'a>
impl<'a> Unpin for Request<'a>
impl<'a> !UnwindSafe for Request<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,