summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@theqtcompany.com>2016-08-26 13:25:09 +0200
committerPaolo Angelelli <paolo.angelelli@theqtcompany.com>2016-08-29 11:41:11 +0000
commit7504b2ce36a90261ba2409e4160570b58d8b38e0 (patch)
tree751a51af1e93f97b059399dff0ac823b79a3e995
parent14fac7ee65202b0af7032aaade16d1611bc43731 (diff)
Fix for multiple city tags mapping to the same field
This patch adds support for both "city" and "town" as Json document candidates for QGeoAddress::city Task-number: QTBUG-55371 Change-Id: I468207d81d61b16ea06034ea143bd3fd34df09b1 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/plugins/geoservices/osm/qgeocodereplyosm.cpp57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
index a0a37672..62abdfdc 100644
--- a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
+++ b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
@@ -71,6 +71,35 @@ void QGeoCodeReplyOsm::abort()
m_reply = 0;
}
+static QGeoAddress parseAddressObject(const QJsonObject &object)
+{
+ QGeoAddress address;
+ address.setText(object.value(QStringLiteral("display_name")).toString());
+ QJsonObject ao = object.value(QStringLiteral("address")).toObject();
+ // setCountry
+ address.setCountry(ao.value(QStringLiteral("country")).toString());
+ // setCountryCode
+ address.setCountryCode(ao.value(QStringLiteral("country_code")).toString());
+ // setState
+ address.setState(ao.value(QStringLiteral("state")).toString());
+ // setCity
+ if (ao.contains(QLatin1String("city")))
+ address.setCity(ao.value(QStringLiteral("city")).toString());
+ else if (ao.contains(QLatin1String("town")))
+ address.setCity(ao.value(QLatin1String("town")).toString());
+ else if (ao.contains(QLatin1String("village")))
+ address.setCity(ao.value(QLatin1String("village")).toString());
+ else
+ address.setCity(ao.value(QLatin1String("hamlet")).toString());
+ // setDistrict
+ address.setDistrict(ao.value(QStringLiteral("suburb")).toString());
+ // setPostalCode
+ address.setPostalCode(ao.value(QStringLiteral("postcode")).toString());
+ // setStreet
+ address.setStreet(ao.value(QStringLiteral("road")).toString());
+ return address;
+}
+
void QGeoCodeReplyOsm::networkReplyFinished()
{
if (!m_reply)
@@ -90,21 +119,9 @@ void QGeoCodeReplyOsm::networkReplyFinished()
coordinate.setLatitude(object.value(QStringLiteral("lat")).toString().toDouble());
coordinate.setLongitude(object.value(QStringLiteral("lon")).toString().toDouble());
- QJsonObject ao = object.value(QStringLiteral("address")).toObject();
-
- QGeoAddress address;
- address.setText(object.value(QStringLiteral("display_name")).toString());
- address.setCountry(ao.value(QStringLiteral("country")).toString());
- address.setCountryCode(ao.value(QStringLiteral("country_code")).toString());
- address.setState(ao.value(QStringLiteral("state")).toString());
- address.setCity(ao.value(QStringLiteral("city")).toString());
- address.setDistrict(ao.value(QStringLiteral("suburb")).toString());
- address.setPostalCode(ao.value(QStringLiteral("postcode")).toString());
- address.setStreet(ao.value(QStringLiteral("road")).toString());
-
QGeoLocation location;
location.setCoordinate(coordinate);
- location.setAddress(address);
+ location.setAddress(parseAddressObject(object));
locations.append(location);
@@ -135,22 +152,10 @@ void QGeoCodeReplyOsm::networkReplyFinished()
}
}
- QJsonObject ao = object.value(QStringLiteral("address")).toObject();
-
- QGeoAddress address;
- address.setText(object.value(QStringLiteral("display_name")).toString());
- address.setCountry(ao.value(QStringLiteral("country")).toString());
- address.setCountryCode(ao.value(QStringLiteral("country_code")).toString());
- address.setState(ao.value(QStringLiteral("state")).toString());
- address.setCity(ao.value(QStringLiteral("city")).toString());
- address.setDistrict(ao.value(QStringLiteral("suburb")).toString());
- address.setPostalCode(ao.value(QStringLiteral("postcode")).toString());
- address.setStreet(ao.value(QStringLiteral("road")).toString());
-
QGeoLocation location;
location.setCoordinate(coordinate);
location.setBoundingBox(rectangle);
- location.setAddress(address);
+ location.setAddress(parseAddressObject(object));
locations.append(location);
}