Commit 663141f1 authored by Volker Krause's avatar Volker Krause
Browse files

Fill in missing country/state information based on the coordinate

Gives us correct location-aware address formatting in more cases.
parent 8ff9e614
Pipeline #133136 passed with stages
in 1 minute and 1 second
......@@ -11,6 +11,7 @@ add_library(KOSMIndoorMapQuick STATIC
target_link_libraries(KOSMIndoorMapQuick PUBLIC
Qt5::Quick
KF5::I18n
KF5::I18nLocaleData
KOSMIndoorMap
)
......
......@@ -6,6 +6,9 @@
#include "osmaddress.h"
#include <KCountry>
#include <KCountrySubdivision>
using namespace KOSMIndoorMap;
OSMAddress::OSMAddress() = default;
......@@ -38,10 +41,22 @@ QString OSMAddress::city() const
QString OSMAddress::state() const
{
return QString::fromUtf8(m_element.tagValue("addr:state"));
const auto state = QString::fromUtf8(m_element.tagValue("addr:state"));
if (!state.isEmpty()) {
return state;
}
const auto s = KCountrySubdivision::fromLocation(m_element.center().latF(), m_element.center().lonF());
return s.isValid() ? s.code().left(3) : QString();
}
QString OSMAddress::country() const
{
return QString::fromUtf8(m_element.tagValue("addr:country", "contact:country"));
const auto country = QString::fromUtf8(m_element.tagValue("addr:country", "contact:country"));
if (!country.isEmpty()) {
return country;
}
const auto c = KCountry::fromLocation(m_element.center().latF(), m_element.center().lonF());
return c.alpha2();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment