summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-09-17 22:54:56 +0200
committerLiang Qi <liang.qi@qt.io>2016-09-17 22:54:56 +0200
commit5d0481603414a4584dbfe89aaba48a6135b9e2d8 (patch)
treea8868da5003265d55a3ff5f2cc380ca41756f582 /src
parent9cf6d7e77fc7029c35af56d943e4267051845c0a (diff)
parent7cfd70fa2f8fd24053d31122ac0a27eb56915895 (diff)
downloadqtlocation-5d0481603414a4584dbfe89aaba48a6135b9e2d8.tar.gz
Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: Ie8986d40efc5a241cb94ba743e343cbb35f66611
Diffstat (limited to 'src')
-rw-r--r--src/location/doc/src/plugins/osm.qdoc4
-rw-r--r--src/plugins/geoservices/osm/qgeocodereplyosm.cpp57
2 files changed, 34 insertions, 27 deletions
diff --git a/src/location/doc/src/plugins/osm.qdoc b/src/location/doc/src/plugins/osm.qdoc
index 75ac104d..1960fae9 100644
--- a/src/location/doc/src/plugins/osm.qdoc
+++ b/src/location/doc/src/plugins/osm.qdoc
@@ -63,7 +63,9 @@ a prefix.
\row
\li osm.useragent
\li User agent string set when making network requests. This parameter should be set to a
- value that uniquely identifies the application.
+ value that uniquely identifies the application. Note that providers might block applications not setting this
+ parameter, leaving it to the stock plugin user agent (e.g., \l {http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy}{Nominatim}
+ for geocoding)
\row
\li osm.mapping.custom.host
\li Url string set when making network requests to the tile server. This parameter should be set to a
diff --git a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
index 807f7a9c..15b1724e 100644
--- a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
+++ b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
@@ -77,6 +77,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)
@@ -96,21 +125,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);
@@ -141,22 +158,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);
}