22QGeoLocation
QMapboxCommon::parseGeoLocation(
const QJsonObject &response)
24 QGeoLocation location;
28 QString streetAddress = response.value(QStringLiteral(
"address")).toString();
33 if (response.value(QStringLiteral(
"place_type")).isArray()) {
34 for (
const QJsonValueConstRef value : response.value(QStringLiteral(
"place_type")).toArray()) {
35 if (!value.isString())
37 if (value.toString() == QStringLiteral(
"address")) {
38 streetAddress.prepend(response.value(QStringLiteral(
"text")).toString() + QLatin1Char(
' '));
44 if (response.value(QStringLiteral(
"properties")).isObject()) {
45 const QJsonObject properties = response.value(QStringLiteral(
"properties")).toObject();
48 const QString addressString = properties.value(QStringLiteral(
"address")).toString();
49 if (!addressString.isEmpty())
50 streetAddress = addressString;
53 address.setStreet(streetAddress);
55 if (response.value(QStringLiteral(
"context")).isArray()) {
56 for (
const QJsonValueConstRef value : response.value(QStringLiteral(
"context")).toArray()) {
57 if (!value.isObject())
60 const QJsonObject object = value.toObject();
61 const QString valueId = object.value(QStringLiteral(
"id")).toString();
62 const QString valueText = object.value(QStringLiteral(
"text")).toString();
64 if (valueId.isEmpty() || valueText.isEmpty())
68 if (valueId.startsWith(QStringLiteral(
"country"))) {
69 address.setCountry(valueText);
70 const QString countryCode = object.value(QStringLiteral(
"short_code")).toString();
71 if (!countryCode.isEmpty())
72 address.setCountryCode(countryCode);
73 }
else if (valueId.startsWith(QStringLiteral(
"region"))) {
74 address.setState(valueText);
75 }
else if (valueId.startsWith(QStringLiteral(
"postcode"))) {
76 address.setPostalCode(valueText);
77 }
else if (valueId.startsWith(QStringLiteral(
"district"))) {
78 address.setDistrict(valueText);
79 }
else if (valueId.startsWith(QStringLiteral(
"place"))) {
80 address.setCity(valueText);
85 const QString placeName = response.value(QStringLiteral(
"place_name")).toString();
88 address.setText(placeName.mid(placeName.indexOf(QLatin1Char(
',')) + 1));
91 location.setAddress(address);
93 QJsonArray bbox = response.value(QStringLiteral(
"bbox")).toArray();
94 double top = bbox.at(3).toDouble();
95 double left = bbox.at(0).toDouble();
96 double bottom = bbox.at(1).toDouble();
97 double right = bbox.at(2).toDouble();
98 location.setBoundingShape(QGeoRectangle(QGeoCoordinate(top, left), QGeoCoordinate(bottom, right)));
100 QJsonArray center = response.value(QStringLiteral(
"center")).toArray();
101 location.setCoordinate(QGeoCoordinate(center.at(1).toDouble(), center.at(0).toDouble()));