Skip to main content

everymap_providers_google/
ext.rs

1use async_trait::async_trait;
2use everymap_core::error::EveryMapResult;
3
4/// Extension trait for Google-specific positioning capabilities.
5///
6/// Provides access to the rich Google Geolocation API response type,
7/// which includes more detail than the core `PositioningResponse`.
8///
9/// ```ignore
10/// use everymap_providers_google::GooglePositionerExt;
11/// let result = positioner.locate(google_options).await?;
12/// ```
13#[async_trait]
14pub trait GooglePositionerExt: Send + Sync {
15    /// Get a position estimate with rich Google response type.
16    /// POST /geolocation/v1/geolocate
17    async fn locate(
18        &self,
19        options: super::domain::positioning::GooglePositioningOptions,
20    ) -> EveryMapResult<super::domain::positioning::GoogleGeolocationResponse>;
21}
22
23/// Extension trait for Google-specific attribute capabilities.
24///
25/// Provides typed access to the Roads API speedLimits endpoints,
26/// which return more detail than the core `AttributeResponse`.
27///
28/// ```ignore
29/// use everymap_providers_google::GoogleAttributeExt;
30/// let limits = provider.get_speed_limits_by_ids(&place_ids, None).await?;
31/// ```
32#[async_trait]
33pub trait GoogleAttributeExt: Send + Sync {
34    /// Get speed limits by place IDs.
35    /// GET /v1/speedLimits?placeId=...&placeId=...&units=...
36    async fn get_speed_limits_by_ids(
37        &self,
38        place_ids: &[String],
39        units: Option<&str>,
40    ) -> EveryMapResult<super::domain::attributes::GoogleSpeedLimitsResponse>;
41
42    /// Get speed limits along a path (snapped to roads).
43    /// GET /v1/speedLimits?path=...&units=...
44    async fn get_speed_limits_along_path(
45        &self,
46        path: &str,
47        units: Option<&str>,
48    ) -> EveryMapResult<super::domain::attributes::GoogleSpeedLimitsResponse>;
49}
50
51// --- Extension trait implementations ---
52
53#[async_trait]
54impl GooglePositionerExt for super::domain::positioning::GooglePositioner {
55    async fn locate(
56        &self,
57        options: super::domain::positioning::GooglePositioningOptions,
58    ) -> EveryMapResult<super::domain::positioning::GoogleGeolocationResponse> {
59        self.locate(options).await
60    }
61}
62
63#[async_trait]
64impl GoogleAttributeExt for super::domain::attributes::GoogleAttributeProvider {
65    async fn get_speed_limits_by_ids(
66        &self,
67        place_ids: &[String],
68        units: Option<&str>,
69    ) -> EveryMapResult<super::domain::attributes::GoogleSpeedLimitsResponse> {
70        self.get_speed_limits_by_ids(place_ids, units).await
71    }
72
73    async fn get_speed_limits_along_path(
74        &self,
75        path: &str,
76        units: Option<&str>,
77    ) -> EveryMapResult<super::domain::attributes::GoogleSpeedLimitsResponse> {
78        self.get_speed_limits_along_path(path, units).await
79    }
80}