void tst_QGeoLocation::isEmpty() { QGeoAddress address; address.setCity(QStringLiteral("Braunschweig")); QVERIFY(!address.isEmpty()); QGeoRectangle boundingBox; boundingBox.setTopLeft(QGeoCoordinate(1, -1)); boundingBox.setBottomRight(QGeoCoordinate(-1, 1)); QVERIFY(!boundingBox.isEmpty()); QGeoLocation location; QVERIFY(location.isEmpty()); // address location.setAddress(address); QVERIFY(!location.isEmpty()); location.setAddress(QGeoAddress()); QVERIFY(location.isEmpty()); // coordinate location.setCoordinate(QGeoCoordinate(1, 2)); QVERIFY(!location.isEmpty()); location.setCoordinate(QGeoCoordinate()); QVERIFY(location.isEmpty()); // bounding box location.setBoundingBox(boundingBox); QVERIFY(!location.isEmpty()); location.setBoundingBox(QGeoRectangle()); QVERIFY(location.isEmpty()); }
/* This property holds the bottom right coordinate of this georectangle. */ void GeoRectangleValueType::setBottomRight(const QGeoCoordinate &coordinate) { QGeoRectangle r = v; if (r.bottomRight() == coordinate) return; r.setBottomRight(coordinate); v = r; }
void QGeoCodeReplyOsm::networkReplyFinished() { if (!m_reply) return; if (m_reply->error() != QNetworkReply::NoError) return; QList<QGeoLocation> locations; QJsonDocument document = QJsonDocument::fromJson(m_reply->readAll()); if (document.isObject()) { QJsonObject object = document.object(); QGeoCoordinate coordinate; coordinate.setLatitude(object.value(QStringLiteral("lat")).toString().toDouble()); coordinate.setLongitude(object.value(QStringLiteral("lon")).toString().toDouble()); QGeoLocation location; location.setCoordinate(coordinate); location.setAddress(parseAddressObject(object)); locations.append(location); setLocations(locations); } else if (document.isArray()) { QJsonArray results = document.array(); for (int i = 0; i < results.count(); ++i) { if (!results.at(i).isObject()) continue; QJsonObject object = results.at(i).toObject(); QGeoCoordinate coordinate; coordinate.setLatitude(object.value(QStringLiteral("lat")).toString().toDouble()); coordinate.setLongitude(object.value(QStringLiteral("lon")).toString().toDouble()); QGeoRectangle rectangle; if (object.contains(QStringLiteral("boundingbox"))) { QJsonArray a = object.value(QStringLiteral("boundingbox")).toArray(); if (a.count() == 4) { rectangle.setTopLeft(QGeoCoordinate(a.at(1).toString().toDouble(), a.at(2).toString().toDouble())); rectangle.setBottomRight(QGeoCoordinate(a.at(0).toString().toDouble(), a.at(3).toString().toDouble())); } } QGeoLocation location; location.setCoordinate(coordinate); location.setBoundingBox(rectangle); location.setAddress(parseAddressObject(object)); locations.append(location); } } setLocations(locations); setFinished(true); m_reply->deleteLater(); m_reply = 0; }
void QGeoCodeReplyOsm::networkReplyFinished() { if (!m_reply) return; if (m_reply->error() != QNetworkReply::NoError) return; QJsonDocument document = QJsonDocument::fromJson(m_reply->readAll()); if (document.isObject()) { QJsonObject object = document.object(); QGeoCoordinate coordinate; 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); QList<QGeoLocation> locations; locations.append(location); setLocations(locations); setFinished(true); } else if (document.isArray()) { QJsonArray results = document.array(); QList<QGeoLocation> locations; for (int i = 0; i < results.count(); ++i) { if (!results.at(i).isObject()) continue; QJsonObject object = results.at(i).toObject(); QGeoCoordinate coordinate; coordinate.setLatitude(object.value(QStringLiteral("lat")).toString().toDouble()); coordinate.setLongitude(object.value(QStringLiteral("lon")).toString().toDouble()); QGeoRectangle rectangle; if (object.contains(QStringLiteral("boundingbox"))) { QJsonArray a = object.value(QStringLiteral("boundingbox")).toArray(); if (a.count() == 4) { rectangle.setTopLeft(QGeoCoordinate(a.at(1).toString().toDouble(), a.at(2).toString().toDouble())); rectangle.setBottomRight(QGeoCoordinate(a.at(0).toString().toDouble(), a.at(3).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.setBoundingBox(rectangle); location.setAddress(address); locations.append(location); } setLocations(locations); setFinished(true); } m_reply->deleteLater(); m_reply = 0; }