diff --git a/map/address_finder.cpp b/map/address_finder.cpp index 0cf23d62ba..7ff121b8a2 100644 --- a/map/address_finder.cpp +++ b/map/address_finder.cpp @@ -487,6 +487,29 @@ search::AddressInfo Framework::GetFeatureAddressInfo(FeatureType const & ft) con return info; } +vector Framework::GetNearbyFeatureStreets(FeatureType const & ft) const +{ + search::ReverseGeocoder const coder(m_model.GetIndex()); + // Need to filter out duplicate street names. + auto const streets = coder.GetNearbyFeatureStreets(ft); + // Reasonable number of different nearby street names to display in UI. + size_t const kMinNumberOfNearbyStreets = 5; + vector results; + // Feature's street from OSM data, if exists, always goes first. + if (streets.second < streets.first.size()) + results.push_back(streets.first[streets.second].m_name); + for (auto const & street : streets.first) + { + auto const e = results.end(); + if (e == find(results.begin(), e, street.m_name)) + { + results.push_back(street.m_name); + if (results.size() >= kMinNumberOfNearbyStreets) + break; + } + } + return results; +} /* void Framework::GetLocality(m2::PointD const & pt, search::AddressInfo & info) const { diff --git a/map/framework.hpp b/map/framework.hpp index dea59d4eb7..29892f53b1 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -479,6 +479,10 @@ public: /// Please use this method for debug purposes only. It always tries to find closest street. search::AddressInfo GetMercatorAddressInfo(m2::PointD const & mercator) const; search::AddressInfo GetFeatureAddressInfo(FeatureType const & ft) const; + /// If feature does not have explicit street in OSM data, first value can be a closest named street. + /// If it does have explicit street name in OSM, it goes first in the returned vector. + /// @returns empty vector if no named streets were found around feature. + vector GetNearbyFeatureStreets(FeatureType const & ft) const; /// Get feature at given point even if it's invisible on the screen. /// TODO(AlexZ): Refactor out other similar methods. /// @returns nullptr if no feature was found at the given mercator point.