google_maps2/geocoding/forward/
with_bounds.rs

1use crate::geocoding::forward::ForwardRequest;
2use crate::types::Bounds;
3
4// -----------------------------------------------------------------------------
5
6impl<'a> ForwardRequest<'a> {
7    /// Specifies a bounding box for biasing results.
8    ///
9    /// ## Arguments
10    ///
11    /// * `bounds` - The bounding box of the viewport within which to bias
12    /// geocode results more prominently. This parameter will only influence,
13    /// not fully restrict, results from the geocoder.
14    ///
15    /// ## Description
16    ///
17    /// [Viewport
18    /// Biasing](https://developers.google.com/maps/documentation/geocoding/intro#Viewports)
19    ///
20    /// In a Geocoding request, you can instruct the Geocoding service to prefer
21    /// results within a given viewport (expressed as a bounding box). You do so
22    /// within the request URL by setting the `bounds` parameter. Note that
23    /// biasing only _prefers_ results within the bounds; if more relevant
24    /// results exist outside of these bounds, they may be included.
25    ///
26    /// The bounds parameter defines the latitude/longitude coordinates of the
27    /// southwest and northeast corners of this bounding box.
28    ///
29    /// For example, a geocode for "Winnetka" generally returns this suburb of
30    /// Chicago. However, adding a `bounds` argument defining a bounding box for
31    /// the San Fernando Valley of Los Angeles results in this geocode returning
32    /// the neighborhood named "Winnetka" in that location.
33    ///
34    /// ## Example
35    ///
36    /// * Specify bounding box for search area:
37    /// ```
38    /// .with_bounds(Bounds {
39    ///     southwest: LatLng::try_from_dec(dec!(51.503_111_7), dec!(-0.129_150_3))?,
40    ///     northeast: LatLng::try_from_dec(dec!(51.503_440_5), dec!(-0.126_003_2))?,
41    /// })
42    /// ```
43
44    pub fn with_bounds(
45        &'a mut self,
46        bounds: impl Into<Bounds>,
47    ) -> &'a mut Self {
48        // Set bounds in ForwardRequest struct.
49        self.bounds = Some(bounds.into());
50        // Return modified ForwardRequest struct to caller.
51        self
52    } // fn
53} // impl