pub struct RouteService { /* private fields */ }Implementations§
Source§impl RouteService
impl RouteService
Sourcepub async fn get_route(
&mut self,
origin: &WayPoint,
destination: &WayPoint,
response_masks: Option<Vec<&str>>,
params: Option<HashMap<String, Value>>,
) -> Result<ComputeRouteResponse>
pub async fn get_route( &mut self, origin: &WayPoint, destination: &WayPoint, response_masks: Option<Vec<&str>>, params: Option<HashMap<String, Value>>, ) -> Result<ComputeRouteResponse>
Get a route.
See https://developers.google.com/maps/documentation/routes/compute_route_directions
origin- Origin waypoint.destination- destination waypoint.response_masks- response field mask. If not specified, all available fields will be included.
Example: vec![“routes.duration”, “routes.distanceMeters”] to return only distanceMeters and duration field for the route. See https://developers.google.com/maps/documentation/routes/choose_fields for more details.params- Optional Additional Parameter. Keys accepted are the following. See ComputeRouteRequestOptinalParams for type detailintermediatestravelModeroutingPreferencepolylineQualitypolylineEncodingdepartureTime: A timestamp in RFC3339 UTC “Zulu” format. Examples: “2014-10-02T15:01:23Z” and “2014-10-02T15:01:23.045123456Z”.arrivalTime: A timestamp in RFC3339 UTC “Zulu” format. Examples: “2014-10-02T15:01:23Z” and “2014-10-02T15:01:23.045123456Z”.computeAlternativeRoutesrouteModifierslanguageCoderegionCodeunitsoptimizeWaypointOrderrequestedReferenceRoutesextraComputationstrafficModeltransitPreferences
Examples found in repository?
examples/route_service.rs (line 49)
23async fn get_route() -> Result<()> {
24 dotenv().ok();
25
26 // api auth
27 let api_key = env::var("API_KEY")?;
28 let mut route_service = RouteService::new_with_api_key(api_key);
29
30 let masks = vec!["routes.duration", "routes.distanceMeters"];
31 let origin = WayPoint::new_from_location(Location::new(37.419734, -122.0827784, None), None)?;
32 let destination = WayPoint::new_from_location(Location::new(35.419734, -100.0827784, None), None)?;
33
34 let mut mid_waypoint_option: HashMap<String, Value> = HashMap::new();
35 mid_waypoint_option.insert("via".to_string(), true.into());
36
37 let mut route_option: HashMap<String, Value> = HashMap::new();
38 // let mid_waypoint = WayPoint::new_from_place_id("ChIJgUbEo8cfqokR5lP9_Wh_DaM", Some(mid_waypoint_option))?;
39 // route_option.insert("intermediates".to_owned(), serde_json::to_value(vec![mid_waypoint.clone()])?);
40 route_option.insert("travelMode".to_owned(), serde_json::to_value(RouteTravelMode::Drive)?);
41 route_option.insert("routingPreference".to_owned(), serde_json::to_value(RoutingPreference::TrafficAwareOptimal)?);
42 // route_option.insert("departureTime".to_owned(), serde_json::to_value(Utc::now() + Duration::seconds(60 * 60 * 24))?);
43 // let route_modifiers = RouteModifiers::new(Some(true), Some(true), Some(true), None, None, None);
44 // route_option.insert("routeModifiers".to_owned(), serde_json::to_value(route_modifiers)?);
45 // route_option.insert("requestedReferenceRoutes".to_owned(), serde_json::to_value(vec![ReferenceRoute::FuelEfficient])?);
46 let transit_preference = TransitPreferences::new(Some(vec![TransitTravelMode::Bus]), None);
47 route_option.insert("transitPreferences".to_owned(), serde_json::to_value(transit_preference)?);
48
49 let response = route_service.get_route(&origin, &destination, Some(masks.clone()), Some(route_option.clone())).await?;
50 println!("response: {}", serde_json::to_string_pretty(&response)?);
51
52
53 // service account auth
54 let filepath: PathBuf = PathBuf::from_str("credentials.json")?;
55 let credentials = ServiceAccountCredentials::from_service_account_file(filepath)?;
56 let mut route_service = RouteService::new_with_credentials(credentials);
57 let response = route_service.get_route(&origin, &destination, Some(masks.clone()), Some(route_option.clone())).await?;
58 println!("response: {}", serde_json::to_string(&response)?);
59
60 Ok(())
61}Source§impl RouteService
impl RouteService
Sourcepub async fn get_route_matrix(
&mut self,
origin: &Vec<RouteMatrixOrigin>,
destination: &Vec<RouteMatrixOrigin>,
response_masks: Option<Vec<&str>>,
params: Option<HashMap<String, Value>>,
) -> Result<Vec<ComputeRouteMatrixResponse>>
pub async fn get_route_matrix( &mut self, origin: &Vec<RouteMatrixOrigin>, destination: &Vec<RouteMatrixOrigin>, response_masks: Option<Vec<&str>>, params: Option<HashMap<String, Value>>, ) -> Result<Vec<ComputeRouteMatrixResponse>>
Calculate the distance and duration of a route for multiple origins and destinations.
See https://developers.google.com/maps/documentation/routes/compute_route_directions
origin- Origin waypoint.destination- destination waypoint.response_masks- response field mask. If not specified, all available fields will be included.
Example: vec![“routes.duration”, “routes.distanceMeters”] to return only distanceMeters and duration field for the route. See https://developers.google.com/maps/documentation/routes/choose_fields for more details.params- Optional Additional Parameter. Keys accepted are the following. See ComputeRouteMatixRequestOptinalParams for type detailintermediatestravelModeroutingPreferencedepartureTime: A timestamp in RFC3339 UTC “Zulu” format. Examples: “2014-10-02T15:01:23Z” and “2014-10-02T15:01:23.045123456Z”.arrivalTime: A timestamp in RFC3339 UTC “Zulu” format. Examples: “2014-10-02T15:01:23Z” and “2014-10-02T15:01:23.045123456Z”.languageCoderegionCodeunitsextraComputationstrafficModeltransitPreferences
Examples found in repository?
examples/route_service.rs (line 80)
64async fn get_route_matrix() -> Result<()> {
65 dotenv().ok();
66
67 // api auth
68 let api_key = env::var("API_KEY")?;
69 let mut route_service = RouteService::new_with_api_key(api_key);
70
71 let masks = vec!["originIndex", "destinationIndex", "status", "condition", "distanceMeters", "duration"];
72 let origin = WayPoint::new_from_location(Location::new(37.419734, -122.0827784, None), None)?;
73 let destination = WayPoint::new_from_location(Location::new(35.419734, -100.0827784, None), None)?;
74
75 let mut route_option: HashMap<String, Value> = HashMap::new();
76 // let mid_waypoint = WayPoint::new_from_place_id("ChIJgUbEo8cfqokR5lP9_Wh_DaM", Some(mid_waypoint_option))?;
77 // route_option.insert("intermediates".to_owned(), serde_json::to_value(vec![mid_waypoint.clone()])?);
78 route_option.insert("travelMode".to_owned(), serde_json::to_value(RouteTravelMode::Drive)?);
79
80 let response = route_service.get_route_matrix(&vec![RouteMatrixOrigin::new(&origin)], &vec![RouteMatrixOrigin::new(&destination)], Some(masks.clone()), Some(route_option.clone())).await?;
81 println!("response: {}", serde_json::to_string_pretty(&response)?);
82
83
84 // service account auth
85 let filepath: PathBuf = PathBuf::from_str("credentials.json")?;
86 let credentials = ServiceAccountCredentials::from_service_account_file(filepath)?;
87 let mut route_service = RouteService::new_with_credentials(credentials);
88 let response = route_service.get_route_matrix(&vec![RouteMatrixOrigin::new(&origin)], &vec![RouteMatrixOrigin::new(&destination)], Some(masks.clone()), Some(route_option.clone())).await?;
89 println!("response: {}", serde_json::to_string_pretty(&response)?);
90
91 Ok(())
92}Source§impl RouteService
impl RouteService
Sourcepub fn new_with_api_key(api_key: String) -> Self
pub fn new_with_api_key(api_key: String) -> Self
Create RouteService Authenticate by using API keys.
api_key- API key to use to authenticate to Google Cloud APIs and services that support API keys.
Examples found in repository?
examples/route_service.rs (line 28)
23async fn get_route() -> Result<()> {
24 dotenv().ok();
25
26 // api auth
27 let api_key = env::var("API_KEY")?;
28 let mut route_service = RouteService::new_with_api_key(api_key);
29
30 let masks = vec!["routes.duration", "routes.distanceMeters"];
31 let origin = WayPoint::new_from_location(Location::new(37.419734, -122.0827784, None), None)?;
32 let destination = WayPoint::new_from_location(Location::new(35.419734, -100.0827784, None), None)?;
33
34 let mut mid_waypoint_option: HashMap<String, Value> = HashMap::new();
35 mid_waypoint_option.insert("via".to_string(), true.into());
36
37 let mut route_option: HashMap<String, Value> = HashMap::new();
38 // let mid_waypoint = WayPoint::new_from_place_id("ChIJgUbEo8cfqokR5lP9_Wh_DaM", Some(mid_waypoint_option))?;
39 // route_option.insert("intermediates".to_owned(), serde_json::to_value(vec![mid_waypoint.clone()])?);
40 route_option.insert("travelMode".to_owned(), serde_json::to_value(RouteTravelMode::Drive)?);
41 route_option.insert("routingPreference".to_owned(), serde_json::to_value(RoutingPreference::TrafficAwareOptimal)?);
42 // route_option.insert("departureTime".to_owned(), serde_json::to_value(Utc::now() + Duration::seconds(60 * 60 * 24))?);
43 // let route_modifiers = RouteModifiers::new(Some(true), Some(true), Some(true), None, None, None);
44 // route_option.insert("routeModifiers".to_owned(), serde_json::to_value(route_modifiers)?);
45 // route_option.insert("requestedReferenceRoutes".to_owned(), serde_json::to_value(vec![ReferenceRoute::FuelEfficient])?);
46 let transit_preference = TransitPreferences::new(Some(vec![TransitTravelMode::Bus]), None);
47 route_option.insert("transitPreferences".to_owned(), serde_json::to_value(transit_preference)?);
48
49 let response = route_service.get_route(&origin, &destination, Some(masks.clone()), Some(route_option.clone())).await?;
50 println!("response: {}", serde_json::to_string_pretty(&response)?);
51
52
53 // service account auth
54 let filepath: PathBuf = PathBuf::from_str("credentials.json")?;
55 let credentials = ServiceAccountCredentials::from_service_account_file(filepath)?;
56 let mut route_service = RouteService::new_with_credentials(credentials);
57 let response = route_service.get_route(&origin, &destination, Some(masks.clone()), Some(route_option.clone())).await?;
58 println!("response: {}", serde_json::to_string(&response)?);
59
60 Ok(())
61}
62
63
64async fn get_route_matrix() -> Result<()> {
65 dotenv().ok();
66
67 // api auth
68 let api_key = env::var("API_KEY")?;
69 let mut route_service = RouteService::new_with_api_key(api_key);
70
71 let masks = vec!["originIndex", "destinationIndex", "status", "condition", "distanceMeters", "duration"];
72 let origin = WayPoint::new_from_location(Location::new(37.419734, -122.0827784, None), None)?;
73 let destination = WayPoint::new_from_location(Location::new(35.419734, -100.0827784, None), None)?;
74
75 let mut route_option: HashMap<String, Value> = HashMap::new();
76 // let mid_waypoint = WayPoint::new_from_place_id("ChIJgUbEo8cfqokR5lP9_Wh_DaM", Some(mid_waypoint_option))?;
77 // route_option.insert("intermediates".to_owned(), serde_json::to_value(vec![mid_waypoint.clone()])?);
78 route_option.insert("travelMode".to_owned(), serde_json::to_value(RouteTravelMode::Drive)?);
79
80 let response = route_service.get_route_matrix(&vec![RouteMatrixOrigin::new(&origin)], &vec![RouteMatrixOrigin::new(&destination)], Some(masks.clone()), Some(route_option.clone())).await?;
81 println!("response: {}", serde_json::to_string_pretty(&response)?);
82
83
84 // service account auth
85 let filepath: PathBuf = PathBuf::from_str("credentials.json")?;
86 let credentials = ServiceAccountCredentials::from_service_account_file(filepath)?;
87 let mut route_service = RouteService::new_with_credentials(credentials);
88 let response = route_service.get_route_matrix(&vec![RouteMatrixOrigin::new(&origin)], &vec![RouteMatrixOrigin::new(&destination)], Some(masks.clone()), Some(route_option.clone())).await?;
89 println!("response: {}", serde_json::to_string_pretty(&response)?);
90
91 Ok(())
92}Sourcepub fn new_with_credentials(
service_account_credentials: ServiceAccountCredentials,
) -> Self
pub fn new_with_credentials( service_account_credentials: ServiceAccountCredentials, ) -> Self
Create RouteService Authenticate by using API keys.
service_account_credentials-ServiceAccountCredentialsto use to authenticate to Google Cloud APIs.
Examples found in repository?
examples/route_service.rs (line 56)
23async fn get_route() -> Result<()> {
24 dotenv().ok();
25
26 // api auth
27 let api_key = env::var("API_KEY")?;
28 let mut route_service = RouteService::new_with_api_key(api_key);
29
30 let masks = vec!["routes.duration", "routes.distanceMeters"];
31 let origin = WayPoint::new_from_location(Location::new(37.419734, -122.0827784, None), None)?;
32 let destination = WayPoint::new_from_location(Location::new(35.419734, -100.0827784, None), None)?;
33
34 let mut mid_waypoint_option: HashMap<String, Value> = HashMap::new();
35 mid_waypoint_option.insert("via".to_string(), true.into());
36
37 let mut route_option: HashMap<String, Value> = HashMap::new();
38 // let mid_waypoint = WayPoint::new_from_place_id("ChIJgUbEo8cfqokR5lP9_Wh_DaM", Some(mid_waypoint_option))?;
39 // route_option.insert("intermediates".to_owned(), serde_json::to_value(vec![mid_waypoint.clone()])?);
40 route_option.insert("travelMode".to_owned(), serde_json::to_value(RouteTravelMode::Drive)?);
41 route_option.insert("routingPreference".to_owned(), serde_json::to_value(RoutingPreference::TrafficAwareOptimal)?);
42 // route_option.insert("departureTime".to_owned(), serde_json::to_value(Utc::now() + Duration::seconds(60 * 60 * 24))?);
43 // let route_modifiers = RouteModifiers::new(Some(true), Some(true), Some(true), None, None, None);
44 // route_option.insert("routeModifiers".to_owned(), serde_json::to_value(route_modifiers)?);
45 // route_option.insert("requestedReferenceRoutes".to_owned(), serde_json::to_value(vec![ReferenceRoute::FuelEfficient])?);
46 let transit_preference = TransitPreferences::new(Some(vec![TransitTravelMode::Bus]), None);
47 route_option.insert("transitPreferences".to_owned(), serde_json::to_value(transit_preference)?);
48
49 let response = route_service.get_route(&origin, &destination, Some(masks.clone()), Some(route_option.clone())).await?;
50 println!("response: {}", serde_json::to_string_pretty(&response)?);
51
52
53 // service account auth
54 let filepath: PathBuf = PathBuf::from_str("credentials.json")?;
55 let credentials = ServiceAccountCredentials::from_service_account_file(filepath)?;
56 let mut route_service = RouteService::new_with_credentials(credentials);
57 let response = route_service.get_route(&origin, &destination, Some(masks.clone()), Some(route_option.clone())).await?;
58 println!("response: {}", serde_json::to_string(&response)?);
59
60 Ok(())
61}
62
63
64async fn get_route_matrix() -> Result<()> {
65 dotenv().ok();
66
67 // api auth
68 let api_key = env::var("API_KEY")?;
69 let mut route_service = RouteService::new_with_api_key(api_key);
70
71 let masks = vec!["originIndex", "destinationIndex", "status", "condition", "distanceMeters", "duration"];
72 let origin = WayPoint::new_from_location(Location::new(37.419734, -122.0827784, None), None)?;
73 let destination = WayPoint::new_from_location(Location::new(35.419734, -100.0827784, None), None)?;
74
75 let mut route_option: HashMap<String, Value> = HashMap::new();
76 // let mid_waypoint = WayPoint::new_from_place_id("ChIJgUbEo8cfqokR5lP9_Wh_DaM", Some(mid_waypoint_option))?;
77 // route_option.insert("intermediates".to_owned(), serde_json::to_value(vec![mid_waypoint.clone()])?);
78 route_option.insert("travelMode".to_owned(), serde_json::to_value(RouteTravelMode::Drive)?);
79
80 let response = route_service.get_route_matrix(&vec![RouteMatrixOrigin::new(&origin)], &vec![RouteMatrixOrigin::new(&destination)], Some(masks.clone()), Some(route_option.clone())).await?;
81 println!("response: {}", serde_json::to_string_pretty(&response)?);
82
83
84 // service account auth
85 let filepath: PathBuf = PathBuf::from_str("credentials.json")?;
86 let credentials = ServiceAccountCredentials::from_service_account_file(filepath)?;
87 let mut route_service = RouteService::new_with_credentials(credentials);
88 let response = route_service.get_route_matrix(&vec![RouteMatrixOrigin::new(&origin)], &vec![RouteMatrixOrigin::new(&destination)], Some(masks.clone()), Some(route_option.clone())).await?;
89 println!("response: {}", serde_json::to_string_pretty(&response)?);
90
91 Ok(())
92}Trait Implementations§
Source§impl Clone for RouteService
impl Clone for RouteService
Source§fn clone(&self) -> RouteService
fn clone(&self) -> RouteService
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RouteService
impl RefUnwindSafe for RouteService
impl Send for RouteService
impl Sync for RouteService
impl Unpin for RouteService
impl UnwindSafe for RouteService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more