diff --git a/map/catalog_headers_provider.cpp b/map/catalog_headers_provider.cpp index 884c1c4a194..9ac7b3f3a4b 100644 --- a/map/catalog_headers_provider.cpp +++ b/map/catalog_headers_provider.cpp @@ -32,3 +32,11 @@ platform::HttpClient::Headers CatalogHeadersProvider::GetHeaders() return web_api::GetCatalogHeaders(params); } + +std::optional CatalogHeadersProvider::GetPositionHeader() +{ + if (!m_positionProvider.GetCurrentPosition()) + return {}; + + return web_api::GetPositionHeader(*m_positionProvider.GetCurrentPosition()); +} diff --git a/map/catalog_headers_provider.hpp b/map/catalog_headers_provider.hpp index df920fc43ae..8ef65444c6f 100644 --- a/map/catalog_headers_provider.hpp +++ b/map/catalog_headers_provider.hpp @@ -8,6 +8,8 @@ #include "platform/http_client.hpp" +#include + class CatalogHeadersProvider { public: @@ -15,6 +17,7 @@ class CatalogHeadersProvider storage::Storage const & storage); platform::HttpClient::Headers GetHeaders(); + std::optional GetPositionHeader(); private: PositionProvider const & m_positionProvider; diff --git a/map/guides_on_map_delegate.cpp b/map/guides_on_map_delegate.cpp index 8f67903672b..a23eff3395e 100644 --- a/map/guides_on_map_delegate.cpp +++ b/map/guides_on_map_delegate.cpp @@ -1,5 +1,7 @@ #include "map/guides_on_map_delegate.hpp" +#include "web_api/request_headers.hpp" + GuidesOnMapDelegate::GuidesOnMapDelegate( std::shared_ptr const & headersProvider) : m_headersProvider(headersProvider) @@ -11,5 +13,12 @@ platform::HttpClient::Headers GuidesOnMapDelegate::GetHeaders() if (!m_headersProvider) return {}; - return m_headersProvider->GetHeaders(); + auto const position = m_headersProvider->GetPositionHeader(); + if (!position) + return {}; + + auto headers = web_api::GetDefaultCatalogHeaders(); + headers.emplace(position->m_name, position->m_value); + + return headers; } diff --git a/platform/http_client.hpp b/platform/http_client.hpp index 547984cfa12..cf7cd1278dc 100644 --- a/platform/http_client.hpp +++ b/platform/http_client.hpp @@ -37,6 +37,12 @@ class HttpClient public: static auto constexpr kNoError = -1; + struct Header + { + std::string m_name; + std::string m_value; + }; + using Headers = std::unordered_map; HttpClient() = default; diff --git a/web_api/request_headers.cpp b/web_api/request_headers.cpp index 2decb9fe55f..a9532936fde 100644 --- a/web_api/request_headers.cpp +++ b/web_api/request_headers.cpp @@ -39,16 +39,23 @@ platform::HttpClient::Headers GetDefaultAuthHeaders() return result; } +platform::HttpClient::Header GetPositionHeader(m2::PointD const & pos) +{ + std::ostringstream latLonStream; + auto const latLon = mercator::ToLatLon(pos); + latLonStream << std::fixed << std::setprecision(3) << latLon.m_lat << "," << latLon.m_lon; + + return {kLatLonHeader, latLonStream.str()}; +} + platform::HttpClient::Headers GetCatalogHeaders(HeadersParams const & params) { platform::HttpClient::Headers result = GetDefaultCatalogHeaders(); if (params.m_currentPosition) { - std::ostringstream latLonStream; - auto const latLon = mercator::ToLatLon(*params.m_currentPosition); - latLonStream << std::fixed << std::setprecision(3) << latLon.m_lat << "," << latLon.m_lon; - result.emplace(kLatLonHeader, latLonStream.str()); + auto const latLon = GetPositionHeader(*params.m_currentPosition); + result.emplace(latLon.m_name, latLon.m_value); } if (!params.m_cityGeoIds.empty()) diff --git a/web_api/request_headers.hpp b/web_api/request_headers.hpp index 99d49c5f7a5..0cc96e8e788 100644 --- a/web_api/request_headers.hpp +++ b/web_api/request_headers.hpp @@ -21,5 +21,6 @@ class HeadersParams platform::HttpClient::Headers GetDefaultCatalogHeaders(); platform::HttpClient::Headers GetDefaultAuthHeaders(); +platform::HttpClient::Header GetPositionHeader(m2::PointD const & pos); platform::HttpClient::Headers GetCatalogHeaders(HeadersParams const & params); } // namespace web_api