ReverseRequest

Struct ReverseRequest 

Source
pub struct ReverseRequest<'r> { /* private fields */ }
Expand description

Look at this Request struct for documentation on how to build your Geocoding API query. The methods implemented for this struct are what’s used to build your request. Reverse geocoding looks up a street address from latitude & longitude coorindates.

Implementations§

Source§

impl<'r> ReverseRequest<'r>

Source

pub fn build(&'r mut self) -> Result<&'r mut Self, Error>

👎Deprecated since 3.8.0: try using the query_string method instead

Builds the URL query string for the HTTP GET request.

§Arguments

This method accepts no arguments.

§Notes
  • The query string is the part of the URL after the ? question mark. For example, in the URL https://example.com/over/there?name=ferret the query string is name=ferret

  • The build method has been removed. It would store the generated query string inside of the request structure.

    This way, the same query string would only have to be generated once and could be used for any subsequent retries. This increased implementation complexity but had very performance little benefit. It has been removed.

    If you want to generate a query string (without the preceding URL), try the query_string method.

Source§

impl<'r> ReverseRequest<'r>

Source

pub const fn new(client: &'r Client, latlng: LatLng) -> Self

Initializes the builder pattern for a Geolocation API query with the required, non-optional parameters.

§Arguments:
  • client ‧ Your application’s Google Maps API client struct.

  • latlng ‧ The latitude and longitude values specifying the location for which you wish to obtain the closest, human-readable address.

Source§

impl ReverseRequest<'_>

Source

pub fn with_language(self, language: impl Into<Language>) -> Self

Specifies the language in which to return results.

§Arguments:
  • language - The language in which to return results.
§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 geocoder attempts to use the preferred language as specified in the Accept-Language header, or the native language of the domain from which the request is sent.

  • The geocoder 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 geocoder 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 and square respectively in Hungarian.

§Example:
  • Set language for result:
.with_language(Language::French)
Source§

impl ReverseRequest<'_>

Source

pub fn with_location_type(self, location_type: impl Into<LocationType>) -> Self

Restricts the results from the geocoder to the specified location type(s).

§Arguments:
  • location_type - A single location-type filter.
§Description:

A filter of one or more location types. If the parameter contains multiple location types, the API returns all addresses that match any of the types. A note about processing: The location_type parameter does not restrict the search to the specified location type(s). Rather, the location_type acts as a post-search filter: the API fetches all results for the specified latlng, then discards those results that do not match the specified location type(s).

  • LocationType::RoofTop returns only the addresses for which Google has location information accurate down to street address precision.

  • LocationType::RangeInterpolated returns only the addresses that reflect an approximation (usually on a road) interpolated between two precise points (such as intersections). An interpolated range generally indicates that rooftop geocodes are unavailable for a street address.

  • LocationType::GeometricCenter returns only geometric centers of a location such as a polyline (for example, a street) or polygon (region).

  • LocationType::Approximate returns only the addresses that are characterized as approximate.

If both result_type and location_type filters are present then the API returns only those results that match both the result_type and the location_type values. If none of the filter values are acceptable, the API returns ZERO_RESULTS.

§Examples:
  • A single location-type filter. This example restricts results to roof- top results:
.with_location_type(LocationType::RoofTop)
  • Multiple location type filters may be stacked together. This example restricts results to roof-top and range-interpolated:
.with_location_type(LocationType::RoofTop)
.with_location_type(LocationType::RangeInterpolated)
Source

pub fn with_location_types<C, L>(self, location_types: C) -> Self
where C: IntoIterator<Item = L>, L: Into<LocationType>,

Restricts the results from the geocoder to the specified location type(s).

§Description

A filter of one or more location types. If the parameter contains multiple location types, the API returns all addresses that match any of the types.

If both result_type and location_type filters are present then the API returns only those results that match both the result_type and the location_type values. If none of the filter values are acceptable, the API returns ZERO_RESULTS.

§Example:
  • Alternatively, multiple location type filters may be passed in a single method call by passing a slice. This example restricts results to roof-top and range-interpolated:
.with_location_types(&[
    LocationType::RoofTop,
    LocationType::RangeInterpolated,
])
§Generics

This method uses generics to improve ergonomics. The C generic is intended to represent any collection that can be iterated over, and the L generic is for any type that can be converted to the LocationType type.

Source§

impl ReverseRequest<'_>

Source

pub fn with_result_type(self, result_type: impl Into<PlaceType>) -> Self

Restricts the results from the geocoder to the specified result type(s).

§Arguments:
  • result_type - A single result type filter.
§Description:

A filter of one or more result types. If the parameter contains multiple result types, the API returns all addresses that match any of the types. A note about processing: The result_type parameter does not restrict the search to the specified location type(s). Rather, the result_type acts as a post-search filter: the API fetches all results for the specified latlng, then discards those results that do not match the specified result type(s). The following values are supported:

  • PlaceType::StreetAddress indicates a precise street address.

  • PlaceType::Route indicates a named route (such as “US 101”).

  • PlaceType::Intersection indicates a major intersection, usually of two major roads.

  • PlaceType::Political indicates a political entity. Usually, this type indicates a polygon of some civil administration.

  • PlaceType::Country indicates the national political entity, and is typically the highest order type returned by the Geocoder.

  • PlaceType::AdministrativeAreaLevel1 indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels. In most cases, PlaceType::AdministrativeAreaLevel1 short names will closely match ISO 3166-2 subdivisions and other widely circulated lists; however this is not guaranteed as our geocoding results are based on a variety OF signals and location data.

  • PlaceType::AdministrativeAreaLevel2 indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.

  • PlaceType::AdministrativeAreaLevel3 indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.

  • PlaceType::AdministrativeAreaLevel4 indicates a fourth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.

  • PlaceType::AdministrativeAreaLevel5 indicates a fifth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.

  • PlaceType::ColloquialArea indicates a commonly-used alternative name for the entity.

  • PlaceType::Locality indicates an incorporated city or town political entity.

  • PlaceType::Sublocality indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: PlaceType::SublocalityLevel1 to PlaceType::SublocalityLevel5. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area.

  • PlaceType::Neighborhood indicates a named neighborhood.

  • PlaceType::Premise indicates a named location, usually a building or collection of buildings with a common name.

  • PlaceType::Subpremise indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name.

  • PlaceType::PostalCode indicates a postal code as used to address postal mail within the country.

  • PlaceType::NaturalFeature indicates a prominent natural feature.

  • PlaceType::Airport indicates an airport.

  • PlaceType::Park indicates a named park.

  • PlaceType::PointOfInterest indicates a named point of interest. Typically, these “POI“s are prominent local entities that don’t easily fit in another category, such as “Empire State Building” or “Eiffel Tower”.

If both result_type and location_type filters are present then the API returns only those results that match both the result_type and the location_type values. If none of the filter values are acceptable, the API returns ZERO_RESULTS.

§Examples:
  • A single result type filter. This example restricts results to the neighbourhood:
.with_result_type(PlaceType::Neighborhood)
  • Multiple component filters may be stacked together. This example restricts results to a neighborhood and a locality:
.with_result_type(PlaceType::Neighborhood)
.with_result_type(PlaceType::Locality)
Source

pub fn with_result_types<C, P>(self, result_types: C) -> Self
where C: IntoIterator<Item = P>, P: Into<PlaceType>,

Restricts the results from the geocoder to the specified result type(s).

§Description

A filter of one or more result types. If the parameter contains multiple results types, the API returns all addresses that match any of the types.

If both result_type and location_type filters are present then the API returns only those results that match both the result_type and the location_type values. If none of the filter values are acceptable, the API returns ZERO_RESULTS.

§Example:
  • Alternatively, multiple result type filters may be passed in a single method call by passing a slice. This example restricts results a neighborhood and a locality:
.with_components(&[
    PlaceType::Neighborhood,
    PlaceType::Locality,
])
§Generics

This method uses generics to improve ergonomics. The C generic is intended to represent any collection that can be iterated over, and the P generic is for any type that can be converted to the PlaceType type.

Source§

impl ReverseRequest<'_>

Source

pub async fn execute(self) -> Result<Response, Error>

Executes the Google Maps Geocoding API reverse request.

§Description

This method will:

  1. Validate the request struct that has been built,

  2. Build a URL and query string for an HTTP GET request,

  3. Perform the HTTP GET request using the reqwest crate.

§Arguments

This method accepts no arguments.

§Errors

This method can fail if:

  • This can fail if the request struct fails validation. For example, parameters in the request conflict with one another, or the request parameters are set in a way that’s incompatible.

    For example, Google Maps Directions API cannot calculate alternative routes if waypoints have been set. This will cause a validation failure.

  • The HTTP client cannot make a connection to the Google Maps API server, or successfully send the request or receive the resposne over the network.

  • The Google Maps API server returns an unexpected response, or data in a format that’s not expected.

Source§

impl ReverseRequest<'_>

Source

pub async fn get(self) -> Result<Response, Error>

👎Deprecated since 3.8.0: try using execute instead

Performs the HTTP get request and returns the response.

§Arguments

This method accepts no arguments.

§Notes
  • The get method for this request has been moved to a get method that’s been generically implemented for all APIs and services, implemented on the google_maps::Client struct.

    Try using execute method for a somewhat similar result. The main difference is that the execute method will validate the request and build the URL string, whereas the previous get implementation (that’s been deprecated) would blindly submit the request, if any.

Trait Implementations§

Source§

impl<'r> Debug for ReverseRequest<'r>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EndPoint for ReverseRequest<'_>

Defines a Google Maps API HTTP end-point for a request.

This trait returns information needed to make connect HTTP GET requests to their API end-point. It also includes some extra information for debugging and rating-limiting.

Source§

fn service_url() -> &'static str

URL for the HTTP end-point. For example, https://maps.googleapis.com/maps/api/directions. This string will be used to build the HTTP requests.
Source§

fn title() -> &'static str

Title of the API request end-point. For example Directions API or Elevation API. This title will be output in tracing messages.
Source§

fn apis() -> &'static [Api]

Returns which APIs are being used. This is used for rate-limiting on an API-basis.
Source§

fn output_format() -> Option<&'static str>

Google Maps accepts xml and json formats. Currently, this crate only supports the json format and this function should only return json for now.
Source§

impl QueryString for ReverseRequest<'_>

Source§

fn query_string(&self) -> String

Builds the URL query string for the HTTP GET request. The query string is generated from the data found in this Request structure.

§Arguments

This method accepts no arguments.

§Notes
  • This function does not validate the request before generating the query string. However, the superior method that generates the query URL does perform validation.

  • The query string is the part of the URL after the ? question mark. For example, in the URL https://example.com/over/there?name=ferret the query string is name=ferret

  • There’s no benefit to working on an owned Request struct (i.e. an owned self versus an borrowed &self). percent-encoding works on borrowed UTF-8 strings. Other types, such as enums and numeric values are converted into strings. Therefore no zero-copy operations are possible with an owned self.

Source§

impl RequestHeaders for ReverseRequest<'_>

Source§

fn request_headers(&self) -> HeaderMap

Returns a map of HTTP header names to values.

These headers will be added to the HTTP request alongside the standard headers like Content-Type.

This API end-point does not use headers so it returns an empty hash map.

Source§

fn send_x_goog_api_key() -> bool

Returns whether the X-Goog-Api-Key header should be set for this request.

Source§

impl Validatable for ReverseRequest<'_>

Source§

fn validate(&self) -> Result<(), Error>

Ensures that the request is valid.

§Arguments

This method accepts no arguments.

§Errors
  • This trait implementation is required for operation but there are currently no validations performed for this request type. This method will always return Ok.

Auto Trait Implementations§

§

impl<'r> Freeze for ReverseRequest<'r>

§

impl<'r> !RefUnwindSafe for ReverseRequest<'r>

§

impl<'r> Send for ReverseRequest<'r>

§

impl<'r> Sync for ReverseRequest<'r>

§

impl<'r> Unpin for ReverseRequest<'r>

§

impl<'r> !UnwindSafe for ReverseRequest<'r>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> QueryUrl for T

Source§

fn query_url(&self) -> Result<String, Error>

Returns the URL query string that represents the request you’ve built.

§Description

Returns the URL that will be used as the query to the Google Maps API.

It is the result of the request builder pattern.

This method can also be useful for records or logging. It can also be used for passing to your HTTP client of choice and executing the HTTP GET request yourself.

§Arguments

This method accepts no arguments.

§Errors
  • This can fail if the request struct fails validation. For example, parameters in the request conflict with one another, or the request parameters are set in a way that’s incompatible.

    For example, Google Maps Directions API cannot calculate alternative routes if waypoints have been set. This will cause a validation failure.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T