google_maps2/types/
geometry.rs

1//! Contains the geocoded latitude/longitude, recommended viewport for
2//! displaying the returned result, the bounding box, and other additional
3//! data.
4
5use crate::types::{Bounds, LatLng, LocationType};
6use rust_decimal::Decimal;
7use serde::{Deserialize, Serialize};
8
9// -----------------------------------------------------------------------------
10//
11/// Contains the geocoded latitude/longitude, recommended viewport for
12/// displaying the returned result, the bounding box, and other additional
13/// data.
14
15#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
16pub struct Geometry {
17    /// Contains the geocoded latitude, longitude value. For normal address
18    /// lookups, this field is typically the most important.
19    pub location: LatLng,
20
21    /// Stores additional data about the specified location.
22    pub location_type: Option<LocationType>,
23
24    /// Contains the recommended viewport for displaying the returned result,
25    /// specified as two latitude/longitude values defining the southwest and
26    /// northeast corner of the viewport bounding box. Generally the viewport is
27    /// used to frame a result when displaying it to a user.
28    pub viewport: Bounds,
29
30    /// Stores the bounding box which can fully contain the returned result.
31    /// Note that these bounds may not match the recommended viewport. (For
32    /// example, San Francisco includes the [Farallon
33    /// islands](https://en.wikipedia.org/wiki/Farallon_Islands), which are
34    /// technically part of the city, but probably should not be returned in the
35    /// viewport.)
36    pub bounds: Option<Bounds>,
37} // struct
38
39// =============================================================================
40
41impl Geometry {
42    // -------------------------------------------------------------------------
43    //
44    /// A helper function for destructuring the optional `bounds` field. If
45    /// the _bounds_ field is populated, this function will return the
46    /// south-west _latitude_. If the _bounds_ field is empty, this function
47    /// will return `None`.
48    /// ```rust
49    /// let bounds_southwest_lat = geocoding.geometry.get_bounds_southwest_lng();
50    /// ```
51
52    #[must_use]
53    pub fn get_bounds_southwest_lat(&self) -> Option<Decimal> {
54        self.bounds.as_ref().map(|bounds| bounds.southwest.lat)
55    } // fn
56
57    // -------------------------------------------------------------------------
58    //
59    /// A helper function for destructuring the optional `bounds` field. If
60    /// the _bounds_ field is populated, this function will return the
61    /// south-west _latitude_. If the _bounds_ field is empty, this function
62    /// will return `None`.
63    /// ```rust
64    /// let bounds_southwest_lng = geocoding.geometry.get_bounds_southwest_lng();
65    /// ```
66
67    #[must_use]
68    pub fn get_bounds_southwest_lng(&self) -> Option<Decimal> {
69        self.bounds.as_ref().map(|bounds| bounds.southwest.lng)
70    } // fn
71
72    // -------------------------------------------------------------------------
73    //
74    /// A helper function for destructuring the optional `bounds` field. If
75    /// the _bounds_ field is populated, this function will return the
76    /// north-east _latitude_. If the _bounds_ field is empty, this function
77    /// will return `None`.
78    /// ```rust
79    /// let bounds_northeast_lat = geocoding.geometry.get_bounds_northeast_lng();
80    /// ```
81
82    #[must_use]
83    pub fn get_bounds_northeast_lat(&self) -> Option<Decimal> {
84        self.bounds.as_ref().map(|bounds| bounds.northeast.lat)
85    } // fn
86
87    // -------------------------------------------------------------------------
88    //
89    /// A helper function for destructuring the optional `bounds` field. If
90    /// the _bounds_ field is populated, this function will return the
91    /// north-east _latitude_. If the _bounds_ field is empty, this function
92    /// will return `None`.
93    /// ```rust
94    /// let bounds_northeast_lng = geocoding.geometry.get_bounds_northeast_lng();
95    /// ```
96
97    #[must_use]
98    pub fn get_bounds_northeast_lng(&self) -> Option<Decimal> {
99        self.bounds.as_ref().map(|bounds| bounds.northeast.lng)
100    } // fn
101} // impl