diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-02-14 20:01:33 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-02-14 20:26:09 -0800 |
commit | 5bf86f6042215780247b972547f8675ef180e158 (patch) | |
tree | 1cb4706caf7b03313aa90334fd5728b2acd40bd6 /qthelper.cpp | |
parent | a081fb34e001e321308e75f9eb2edc422ba61f8c (diff) | |
download | subsurface-5bf86f6042215780247b972547f8675ef180e158.tar.gz |
Proof of concept for reverse geo location
When reading a pre-v3 XML file, we now do reverse geo lookups on the GPS
coordinates and add the country to the dive site notes. Eventually this
wants to be a tag (once we implement tags for dive sites).
This is going to add quite a bit of delay when people open a V2 XML file -
depending on how many distinct GPS fixes they have. In my case with 127
GPS fixes it took about 20 seconds to open the file...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qthelper.cpp')
-rw-r--r-- | qthelper.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/qthelper.cpp b/qthelper.cpp index 8d4703b0a..a4b644304 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1,6 +1,10 @@ #include "qthelper.h" +#include "helpers.h" #include "gettextfromc.h" #include "statistics.h" +#include "subsurfacewebservices.h" +#include "usersurvey.h" +#include "membuffer.h" #include <exif.h> #include "file.h" #include <QFile> @@ -8,6 +12,15 @@ #include <QDir> #include <QDebug> #include <QSettings> +#include <QJsonDocument> +#include <QJsonArray> +#include <QJsonObject> +#include <QNetworkReply> +#include <QNetworkRequest> +#include <QNetworkAccessManager> +#include <QUrlQuery> +#include <QEventLoop> + #include <libxslt/documents.h> #define translate(_context, arg) trGettext(arg) @@ -342,3 +355,28 @@ void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsedOrdered) } qSort(gasUsedOrdered.begin(), gasUsedOrdered.end(), lessThan); } + +extern "C" void reverseGeoLookup(degrees_t latitude, degrees_t longitude, uint32_t uuid) +{ + QNetworkRequest request; + QNetworkAccessManager *rgl = new QNetworkAccessManager(); + request.setUrl(QString("http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&accept-language=%1&lat=%2&lon=%3") + .arg(uiLanguage(NULL)).arg(latitude.udeg / 1000000.0).arg(longitude.udeg / 1000000.0)); + request.setRawHeader("Accept", "text/json"); + request.setRawHeader("User-Agent", UserSurvey::getUserAgent().toUtf8()); + QNetworkReply *reply = rgl->get(request); + QEventLoop loop; + QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + QJsonParseError errorObject; + QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &errorObject); + if (errorObject.error != QJsonParseError::NoError) { + qDebug() << errorObject.errorString(); + } else { + QJsonObject obj = jsonDoc.object(); + QJsonObject address = obj.value("address").toObject(); + qDebug() << "found country:" << address.value("country").toString(); + struct dive_site *ds = get_dive_site_by_uuid(uuid); + ds->notes = add_to_string(ds->notes, "countrytag: %s", address.value("country").toString().toUtf8().data()); + } +} |