[][src]Struct google_maps::ClientSettings

pub struct ClientSettings {
    pub key: String,
    pub max_retries: u8,
    pub max_backoff: u32,
    pub rate_limit: RequestRate,
}

Use the ClientSettings struct's implemented methods to set your Google API key and other settings such as: rate limiting, maxium retries, & retry delay times for your requests.

This structure contains your API key - the preferred way for authenticating with the Google Maps Platform APIs, your request rate limit settings, and your automatic retry settings.

How to use this structure's methods in a builder pattern:

let mut my_settings = ClientSettings::new(YOUR_GOOGLE_API_KEY_HERE)
    .with_max_delay(std::time::Duration::from_secs(32))
    .with_max_retries(10)
    .with_rate(Api::All, 1, std::time::Duration::from_secs(2))
    .finalize();

Fields

key: String

Your application's API key. This key identifies your application for purposes of quota management. Learn how to get a key. Contains the application's API key and other settings.

max_retries: u8

Certain network & server-side errors may be successful if retried with the same payload. This parameter sets the maximum number of times the client should retry before giving up.

max_backoff: u32

It's okay to continue retrying once you reach the max_backoff time. Retries after this point do not need to continue increasing backoff time. For example, if a client uses an max_backoff time of 64 seconds, then after reaching this value, the client can retry every 64 seconds. At some point, clients should be prevented from retrying infinitely.

How long clients should wait between retries and how many times they should retry depends on your use case and network conditions. For example, mobile clients of an application may need to retry more times and for longer intervals when compared to desktop clients of the same application.

rate_limit: RequestRate

Rate limits for each of the Google Cloud Maps Platform APIs.

Implementations

impl ClientSettings[src]

pub fn finalize(&self) -> ClientSettings[src]

Completes the builder pattern into a final structure.

Arguments:

This method accepts no arguments.

impl ClientSettings[src]

pub fn new(key: &str) -> ClientSettings[src]

Initialize the settings needed for a Google Cloud Maps API transaction.

pub fn directions(&mut self, origin: Location, destination: Location) -> Request[src]

The Directions API is a service that calculates directions between locations. You can search for directions for several modes of transportation, including transit, driving, walking, or cycling.

directions(
    // Origin: Canadian Museum of Nature
    Location::Address(String::from("240 McLeod St, Ottawa, ON K2P 2R1")),
    // Destination: Canada Science and Technology Museum
    Location::LatLng(LatLng::try_from(dec!(45.403_509), dec!(-75.618_904)).unwrap()),
)

pub fn distance_matrix(
    &mut self,
    origins: Vec<Waypoint>,
    destinations: Vec<Waypoint>
) -> Request
[src]

The Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations, based on the recommended route between start and end points.

distance_matrix(
    // Origins
    vec![
        // Microsoft
        Waypoint::Address(String::from("One Microsoft Way, Redmond, WA 98052, United States")),
        // Cloudflare
        Waypoint::Address(String::from("101 Townsend St, San Francisco, CA 94107, United States")),
    ],
    // Destinations
    vec![
        // Google
        Waypoint::PlaceId(String::from("ChIJj61dQgK6j4AR4GeTYWZsKWw")),
        // Mozilla
        Waypoint::LatLng(LatLng::try_from(dec!(37.387_316), dec!(-122.060_008)).unwrap()),
    ],
)

pub fn elevation(&mut self) -> Request[src]

The Elevation API provides elevation data for all locations on the surface of the earth, including depth locations on the ocean floor (which return negative values).

pub fn geocoding(&mut self) -> ForwardRequest[src]

The Geocoding API is a service that provides geocoding and reverse geocoding of addresses. Geocoding is the process of converting addresses (like a street address) into geographic coordinates (like latitude and longitude), which you can use to place markers on a map, or position the map.

pub fn reverse_geocoding(&mut self, latlng: LatLng) -> ReverseRequest[src]

The Geocoding API is a service that provides geocoding and reverse geocoding of addresses. Reverse geocoding is the process of converting geographic coordinates into a human-readable address.

reverse_geocoding(
    // 10 Downing St, Westminster, London
    LatLng::try_from(dec!(51.503_364), dec!(-0.127_625)).unwrap(),
)

pub fn time_zone(
    &mut self,
    location: LatLng,
    timestamp: DateTime<Utc>
) -> Request
[src]

The Time Zone API provides time offset data for locations on the surface of the earth. You request the time zone information for a specific latitude/longitude pair and date. The API returns the name of that time zone, the time offset from UTC, and the daylight savings offset.

time_zone(
     // St. Vitus Cathedral in Prague, Czechia
     LatLng::try_from(dec!(50.090_903), dec!(14.400_512)).unwrap(),
     // Tuesday February 23, 2020 @ 6:00:00 pm
     NaiveDate::from_ymd(2020, 2, 23).and_hms(18, 00, 0)
)

impl ClientSettings[src]

pub fn with_max_delay(&mut self, max_delay: &Duration) -> &mut ClientSettings[src]

Sets the maximum delay between request retries upon consecutive failures.

Arguments

  • max_delay ‧ The maximum delay between request retries.

Description

Client will continue retrying once you the max_delay time is reached. Retries after this point will not continue increasing backoff time. For example, if a client uses an max_delay time of 64 seconds, then after reaching this value, the client can retry every 64 seconds.

How long clients should wait between retries and how many times they should retry depends on your use case and network conditions. For example, mobile clients of an application may need to retry more times and for longer intervals when compared to desktop clients of the same application.

Example:

  • Sets the maximum delay between request retries to 32 seconds:
.with_max_delay(std::time::Duration::from_secs(32))

impl ClientSettings[src]

pub fn with_max_retries(&mut self, max_retries: u8) -> &mut ClientSettings[src]

Sets the maximum number of retries upon a series of request failures.

Arguments

  • max_retries ‧ The maximum number of request retries.

Example:

  • Sets the maximum number of retries to 10:
.with_max_retries(10)

impl ClientSettings[src]

pub fn with_rate(
    &mut self,
    api: &Api,
    requests: u16,
    per_duration: Duration
) -> &mut ClientSettings
[src]

Sets the rate limit for the specified API.

Arguments

  • api ‧ Which Google Maps API are you setting the rate limit for? For example, Api::Directions, Api::DistanceMatrix, Api::Elevation, Api::Geocoding, Api::TimeZone, and so on. The Api::All rate limit is applied to all Google Maps API requests in addition to the per-API rate limits.

  • requests ‧ The number of requests the client library is attempting to target. For example, 2 requests per 1 hour.

  • duration ‧ The duration for the targeted request rate. For example, 1 request per 1 minute. This can be defined using the std::time::Duration methods.

Examples:

The following examples show how one might try to limit the request rate to achieve maximum throughput while minimizing charges by Google.

The following rates are subject to change by Google. Please review the current Google Maps Platform billing rates.

This Google client library's rate limiting is not persistent. If your program is often restarted, it is easily possible to exceed Google's monthly free credit. These are approximations and examples.

To accurately minimize billing charges by Google, please use the Google Cloud Platform Console IAM & admin to set quotas for each API on the server's side.

You are responsible for all charges. Use with care.

use std::time::Duration;

// Assumptions:
// - $200.00 USD monthly free credit from Google. Thanks, guys!
// - 2,629,746 seconds in a month.
const GOOGLE_CREDIT: f64 = 200.0;
const SECONDS_PER_MONTH: u64 = 2_629_746;
  • Directions API. You are billed for this SKU when your request does not use live traffic information, arrival or departure times, < 10 waypoints, and no waypoint optimization, $0.005 USD per request.
.with_rate(Api::Directions, (GOOGLE_CREDIT / 0.005) as u16, Duration::from_secs(SECONDS_PER_MONTH))
  • Directions Advanced API. You are billed for this SKU when your request requires live traffic information, > 10 waypoints, and/or waypoint optimization, $0.01 per request.
.with_rate(Api::Directions, (GOOGLE_CREDIT / 0.01) as u16, Duration::from_secs(SECONDS_PER_MONTH))
  • Distance Matrix API. You are billed for this SKU when your requests do not require live traffic information, $0.005 per element. The below rate assumes an average of 10 elements per request.
.with_rate(
    Api::DistanceMatrix,
    (GOOGLE_CREDIT / (0.005 * 10.0)) as u16,
    Duration::from_secs(SECONDS_PER_MONTH)
)
  • Distance Matrix Advanced API. You are billed for this SKU when your requests require live traffic information, $0.01 USD per element. The below rate assumes an average of 10 elements per request.
.with_rate(
    Api::DistanceMatrix,
    (GOOGLE_CREDIT / (0.01 * 10.0)) as u16,
    Duration::from_secs(SECONDS_PER_MONTH)
)
.with_rate(Api::Elevation, (GOOGLE_CREDIT / 0.005) as u16, Duration::from_secs(SECONDS_PER_MONTH))
.with_rate(Api::Geocoding, (GOOGLE_CREDIT / 0.005) as u16, Duration::from_secs(SECONDS_PER_MONTH))
.with_rate(Api::TimeZone, (GOOGLE_CREDIT / 0.005) as u16, Duration::from_secs(SECONDS_PER_MONTH))

Trait Implementations

impl Clone for ClientSettings[src]

impl Debug for ClientSettings[src]

impl Eq for ClientSettings[src]

impl Ord for ClientSettings[src]

impl PartialEq<ClientSettings> for ClientSettings[src]

impl PartialOrd<ClientSettings> for ClientSettings[src]

impl StructuralEq for ClientSettings[src]

impl StructuralPartialEq for ClientSettings[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,