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()); }
QPlaceSearchReply *QPlaceManagerEngineOsm::search(const QPlaceSearchRequest &request) { bool unsupported = false; // Only public visibility supported unsupported |= request.visibilityScope() != QLocation::UnspecifiedVisibility && request.visibilityScope() != QLocation::PublicVisibility; unsupported |= request.searchTerm().isEmpty() && request.categories().isEmpty(); if (unsupported) return QPlaceManagerEngine::search(request); QUrlQuery queryItems; queryItems.addQueryItem(QStringLiteral("format"), QStringLiteral("jsonv2")); //queryItems.addQueryItem(QStringLiteral("accept-language"), QStringLiteral("en")); QGeoRectangle boundingBox; QGeoShape searchArea = request.searchArea(); switch (searchArea.type()) { case QGeoShape::CircleType: { QGeoCircle c(searchArea); qreal radius = c.radius(); if (radius < 0) radius = 50000; boundingBox = QGeoRectangle(c.center().atDistanceAndAzimuth(radius, -45), c.center().atDistanceAndAzimuth(radius, 135)); break; } case QGeoShape::RectangleType: boundingBox = searchArea; break; default: ; } if (!boundingBox.isEmpty()) { queryItems.addQueryItem(QStringLiteral("bounded"), QStringLiteral("1")); QString coordinates; coordinates = QString::number(boundingBox.topLeft().longitude()) + QLatin1Char(',') + QString::number(boundingBox.topLeft().latitude()) + QLatin1Char(',') + QString::number(boundingBox.bottomRight().longitude()) + QLatin1Char(',') + QString::number(boundingBox.bottomRight().latitude()); queryItems.addQueryItem(QStringLiteral("viewbox"), coordinates); } QStringList queryParts; if (!request.searchTerm().isEmpty()) queryParts.append(request.searchTerm()); foreach (const QPlaceCategory &category, request.categories()) { QString id = category.categoryId(); int index = id.indexOf(QLatin1Char('=')); if (index != -1) id = id.mid(index+1); queryParts.append(QLatin1Char('[') + id + QLatin1Char(']')); } queryItems.addQueryItem(QStringLiteral("q"), queryParts.join(QLatin1Char('+'))); QVariantMap parameters = request.searchContext().toMap(); QStringList placeIds = parameters.value(QStringLiteral("ExcludePlaceIds")).toStringList(); if (!placeIds.isEmpty()) queryItems.addQueryItem(QStringLiteral("exclude_place_ids"), placeIds.join(QLatin1Char(','))); queryItems.addQueryItem(QStringLiteral("addressdetails"), QStringLiteral("1")); QUrl requestUrl(m_urlPrefix); requestUrl.setQuery(queryItems); QNetworkReply *networkReply = m_networkManager->get(QNetworkRequest(requestUrl)); QPlaceSearchReplyOsm *reply = new QPlaceSearchReplyOsm(request, networkReply, this); connect(reply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(reply, SIGNAL(error(QPlaceReply::Error,QString)), this, SLOT(replyError(QPlaceReply::Error,QString))); return reply; }