google_maps/geocoding/reverse/
with_location_types.rs

1use crate::types::LocationType;
2
3// -----------------------------------------------------------------------------
4
5impl crate::geocoding::ReverseRequest<'_> {
6    /// Restricts the results from the geocoder to the specified location
7    /// type(s).
8    ///
9    /// # Arguments:
10    ///
11    /// * `location_type` - A single location-type filter.
12    ///
13    /// # Description:
14    ///
15    /// A filter of one or more location types. If the parameter contains
16    /// multiple location types, the API returns all addresses that match any of
17    /// the types. A note about processing: The `location_type` parameter does
18    /// not _restrict_ the search to the specified location type(s). Rather, the
19    /// `location_type` acts as a post-search filter: the API fetches all
20    /// results for the specified `latlng`, then discards those results that do
21    /// not match the specified location type(s).
22    ///
23    /// * `LocationType::RoofTop` returns only the addresses for which Google
24    ///   has location information accurate down to street address precision.
25    ///
26    /// * `LocationType::RangeInterpolated` returns only the addresses that
27    ///   reflect an approximation (usually on a road) interpolated between two
28    ///   precise points (such as intersections). An interpolated range
29    ///   generally indicates that rooftop geocodes are unavailable for a street
30    ///   address.
31    ///
32    /// * `LocationType::GeometricCenter` returns only geometric centers of a
33    ///   location such as a polyline (for example, a street) or polygon
34    ///   (region).
35    ///
36    /// * `LocationType::Approximate` returns only the addresses that are
37    ///   characterized as approximate.
38    ///
39    /// If both `result_type` and `location_type` filters are present then the
40    /// API returns only those results that match both the `result_type` and the
41    /// `location_type values`. If none of the filter values are acceptable, the
42    /// API returns `ZERO_RESULTS`.
43    ///
44    /// # Examples:
45    ///
46    /// * A single location-type filter. This example restricts results to roof-
47    ///   top results:
48    ///
49    /// ```rust
50    /// .with_location_type(LocationType::RoofTop)
51    /// ```
52    ///
53    /// * Multiple location type filters may be stacked together. This example
54    ///   restricts results to roof-top and range-interpolated:
55    ///
56    /// ```rust
57    /// .with_location_type(LocationType::RoofTop)
58    /// .with_location_type(LocationType::RangeInterpolated)
59    /// ```
60    #[must_use] pub fn with_location_type(
61        mut self,
62        location_type: impl Into<LocationType>
63    ) -> Self {
64        self.location_types.push(location_type.into());
65        // Return modified ReverseRequest struct to caller.
66        self
67    } // fn
68
69    /// Restricts the results from the geocoder to the specified location
70    /// type(s).
71    ///
72    /// # Description
73    ///
74    /// A filter of one or more location types. If the parameter contains
75    /// multiple location types, the API returns all addresses that match any of
76    /// the types.
77    ///
78    /// If both `result_type` and `location_type` filters are present then the
79    /// API returns only those results that match both the `result_type` and the
80    /// `location_type values`. If none of the filter values are acceptable, the
81    /// API returns `ZERO_RESULTS`.
82    ///
83    /// # Example:
84    ///
85    /// * Alternatively, multiple location type filters may be passed in a
86    ///   single method call by passing a slice. This example restricts results
87    ///   to roof-top and range-interpolated:
88    ///
89    /// ```rust
90    /// .with_location_types(&[
91    ///     LocationType::RoofTop,
92    ///     LocationType::RangeInterpolated,
93    /// ])
94    /// ```
95    ///
96    /// # Generics
97    ///
98    /// This method uses generics to improve ergonomics. The `C` generic is
99    /// intended to represent any collection that can be iterated over, and the
100    /// `L` generic is for any type that can be converted to the `LocationType`
101    /// type.
102    #[must_use] pub fn with_location_types<C, L>(
103        mut self,
104        location_types: C
105    ) -> Self
106    where
107        C: IntoIterator<Item = L>,
108        L: Into<LocationType> {
109        // Add location types to ReverseRequest struct.
110        self.location_types.extend(location_types.into_iter().map(Into::into));
111        // Return modified ReverseRequest struct to caller.
112        self
113    } // fn
114} // impl