Commit d1bac5cd authored by Volker Krause's avatar Volker Krause

Implement name-based location queries for Navita too

parent 86a5d92d
......@@ -162,8 +162,10 @@ bool NavitiaBackend::queryLocation(LocationReply *reply, QNetworkAccessManager *
QStringLiteral("/places_nearby")
);
// TODO distance
} else if (!req.name().isEmpty()) {
url.setPath(QStringLiteral("/v1/places"));
query.addQueryItem(QStringLiteral("q"), req.name());
} else {
// TODO
return false;
}
......@@ -181,7 +183,7 @@ bool NavitiaBackend::queryLocation(LocationReply *reply, QNetworkAccessManager *
if (reply->request().hasCoordinate()) {
addResult(reply, NavitiaParser::parsePlacesNearby(netReply->readAll()));
} else {
// TODO
addResult(reply, NavitiaParser::parsePlaces(netReply->readAll()));
}
break;
case QNetworkReply::ContentNotFoundError:
......
......@@ -232,7 +232,6 @@ std::vector<Departure> NavitiaParser::parseDepartures(const QByteArray &data)
std::vector<Location> NavitiaParser::parsePlacesNearby(const QByteArray &data)
{
qDebug().noquote() << data;
const auto topObj = QJsonDocument::fromJson(data).object();
const auto placesNearby = topObj.value(QLatin1String("places_nearby")).toArray();
......@@ -246,6 +245,21 @@ std::vector<Location> NavitiaParser::parsePlacesNearby(const QByteArray &data)
return res;
}
std::vector<Location> NavitiaParser::parsePlaces(const QByteArray &data)
{
const auto topObj = QJsonDocument::fromJson(data).object();
const auto placesNearby = topObj.value(QLatin1String("places")).toArray();
std::vector<Location> res;
res.reserve(placesNearby.size());
for (const auto &v : placesNearby) {
res.push_back(parseWrappedLocation(v.toObject()));
}
return res;
}
QString NavitiaParser::parseErrorMessage(const QByteArray &data)
{
const auto topObj = QJsonDocument::fromJson(data).object();
......
......@@ -35,6 +35,7 @@ namespace NavitiaParser
std::vector<Journey> parseJourneys(const QByteArray &data);
std::vector<Departure> parseDepartures(const QByteArray &data);
std::vector<Location> parsePlacesNearby(const QByteArray &data);
std::vector<Location> parsePlaces(const QByteArray &data);
QString parseErrorMessage(const QByteArray &data);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment