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>
impl<'r> ReverseRequest<'r>
Sourcepub fn build(&'r mut self) -> Result<&'r mut Self, Error>
👎Deprecated since 3.8.0: try using the query_string method instead
pub fn build(&'r mut self) -> Result<&'r mut Self, Error>
query_string method insteadBuilds 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 URLhttps://example.com/over/there?name=ferretthe query string isname=ferret -
The
buildmethod 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_stringmethod.
Source§impl<'r> ReverseRequest<'r>
impl<'r> ReverseRequest<'r>
Sourcepub const fn new(client: &'r Client, latlng: LatLng) -> Self
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<'_>
impl ReverseRequest<'_>
Sourcepub fn with_language(self, language: impl Into<Language>) -> Self
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
languageis not supplied, the geocoder attempts to use the preferred language as specified in theAccept-Languageheader, 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<'_>
impl ReverseRequest<'_>
Sourcepub fn with_location_type(self, location_type: impl Into<LocationType>) -> Self
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::RoofTopreturns only the addresses for which Google has location information accurate down to street address precision. -
LocationType::RangeInterpolatedreturns 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::GeometricCenterreturns only geometric centers of a location such as a polyline (for example, a street) or polygon (region). -
LocationType::Approximatereturns 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)Sourcepub fn with_location_types<C, L>(self, location_types: C) -> Self
pub fn with_location_types<C, L>(self, location_types: C) -> Self
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<'_>
impl ReverseRequest<'_>
Sourcepub fn with_result_type(self, result_type: impl Into<PlaceType>) -> Self
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::StreetAddressindicates a precise street address. -
PlaceType::Routeindicates a named route (such as “US 101”). -
PlaceType::Intersectionindicates a major intersection, usually of two major roads. -
PlaceType::Politicalindicates a political entity. Usually, this type indicates a polygon of some civil administration. -
PlaceType::Countryindicates the national political entity, and is typically the highest order type returned by the Geocoder. -
PlaceType::AdministrativeAreaLevel1indicates 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::AdministrativeAreaLevel1short 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::AdministrativeAreaLevel2indicates 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::AdministrativeAreaLevel3indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels. -
PlaceType::AdministrativeAreaLevel4indicates a fourth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels. -
PlaceType::AdministrativeAreaLevel5indicates a fifth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels. -
PlaceType::ColloquialAreaindicates a commonly-used alternative name for the entity. -
PlaceType::Localityindicates an incorporated city or town political entity. -
PlaceType::Sublocalityindicates a first-order civil entity below a locality. For some locations may receive one of the additional types:PlaceType::SublocalityLevel1toPlaceType::SublocalityLevel5. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area. -
PlaceType::Neighborhoodindicates a named neighborhood. -
PlaceType::Premiseindicates a named location, usually a building or collection of buildings with a common name. -
PlaceType::Subpremiseindicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name. -
PlaceType::PostalCodeindicates a postal code as used to address postal mail within the country. -
PlaceType::NaturalFeatureindicates a prominent natural feature. -
PlaceType::Airportindicates an airport. -
PlaceType::Parkindicates a named park. -
PlaceType::PointOfInterestindicates 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)Sourcepub fn with_result_types<C, P>(self, result_types: C) -> Self
pub fn with_result_types<C, P>(self, result_types: C) -> Self
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<'_>
impl ReverseRequest<'_>
Sourcepub async fn execute(self) -> Result<Response, Error>
pub async fn execute(self) -> Result<Response, Error>
Executes the Google Maps Geocoding API reverse request.
§Description
This method will:
-
Validate the request
structthat has been built, -
Build a URL and query string for an HTTP GET request,
§Arguments
This method accepts no arguments.
§Errors
This method can fail if:
-
This can fail if the request
structfails 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<'_>
impl ReverseRequest<'_>
Sourcepub async fn get(self) -> Result<Response, Error>
👎Deprecated since 3.8.0: try using execute instead
pub async fn get(self) -> Result<Response, Error>
execute insteadPerforms the HTTP get request and returns the response.
§Arguments
This method accepts no arguments.
§Notes
-
The
getmethod for this request has been moved to agetmethod that’s been generically implemented for all APIs and services, implemented on thegoogle_maps::Clientstruct.Try using
executemethod for a somewhat similar result. The main difference is that the execute method will validate the request and build the URL string, whereas the previousgetimplementation (that’s been deprecated) would blindly submit the request, if any.
Trait Implementations§
Source§impl<'r> Debug for ReverseRequest<'r>
impl<'r> Debug for ReverseRequest<'r>
Source§impl EndPoint for ReverseRequest<'_>
Defines a Google Maps API HTTP end-point for a request.
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
fn service_url() -> &'static str
https://maps.googleapis.com/maps/api/directions. This string will be
used to build the HTTP requests.Source§fn title() -> &'static str
fn title() -> &'static str
Directions API or
Elevation API. This title will be output in tracing messages.Source§fn apis() -> &'static [Api]
fn apis() -> &'static [Api]
Source§fn output_format() -> Option<&'static str>
fn output_format() -> Option<&'static str>
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<'_>
impl QueryString for ReverseRequest<'_>
Source§fn query_string(&self) -> String
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 URLhttps://example.com/over/there?name=ferretthe query string isname=ferret -
There’s no benefit to working on an owned
Requeststruct (i.e. an ownedselfversus 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 ownedself.
Source§impl RequestHeaders for ReverseRequest<'_>
impl RequestHeaders for ReverseRequest<'_>
Source§fn request_headers(&self) -> HeaderMap
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
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<'_>
impl Validatable for ReverseRequest<'_>
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> 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> QueryUrl for T
impl<T> QueryUrl for T
Source§fn query_url(&self) -> Result<String, Error>
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
structfails 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.