7#include "latitudeservice.h"
10#include <QJsonDocument>
18namespace LatitudeService
25static const QUrl GoogleApisUrl(QStringLiteral(
"https://www.googleapis.com"));
26static const QString LocationBasePath(QStringLiteral(
"/latitude/v1/location"));
27static const QString CurrentLocationBasePath(QStringLiteral(
"/latitude/v1/currentLocation"));
37 const QVariantMap info = data.value(QStringLiteral(
"data")).toMap();
39 return Private::parseLocation(info);
47 map.insert(QStringLiteral(
"kind"), QStringLiteral(
"latitude#location"));
48 map.insert(QStringLiteral(
"latitude"),
QString::number(location->latitude()));
49 map.insert(QStringLiteral(
"longitude"),
QString::number(location->longitude()));
51 if (location->timestamp() != 0) {
52 map.insert(QStringLiteral(
"timestampMs"), location->timestamp());
54 if (location->accuracy() != -1) {
55 map.insert(QStringLiteral(
"accuracy"), location->accuracy());
57 if (location->speed() != -1) {
58 map.insert(QStringLiteral(
"speed"), location->speed());
60 if (location->heading() != -1) {
61 map.insert(QStringLiteral(
"heading"), location->heading());
64 map.insert(QStringLiteral(
"altitude"), location->altitude());
66 if (location->altitudeAccuracy() != 0) {
67 map.insert(QStringLiteral(
"altitudeAccuracy"), location->altitudeAccuracy());
70 output.insert(QStringLiteral(
"data"), map);
84 const QVariantMap data = map.value(QStringLiteral(
"data")).toMap();
85 const QVariantList items = data.value(QStringLiteral(
"items")).toList();
88 QVariantMap location = c.
toMap();
89 output << Private::parseLocation(location).dynamicCast<
Object>();
95LocationPtr Private::parseLocation(
const QVariantMap &map)
99 if (map.contains(QStringLiteral(
"timestampMs"))) {
100 location->setTimestamp(map.value(QStringLiteral(
"timestampMs")).toULongLong());
102 if (map.contains(QStringLiteral(
"latitude"))) {
103 location->setLatitude(map.value(QStringLiteral(
"latitude")).toFloat());
105 if (
map.contains(QStringLiteral(
"longitude"))) {
106 location->setLongitude(
map.value(QStringLiteral(
"longitude")).toFloat());
108 if (
map.contains(QStringLiteral(
"accuracy"))) {
109 location->setAccuracy(
map.value(QStringLiteral(
"accuracy")).toInt());
111 if (
map.contains(QStringLiteral(
"speed"))) {
112 location->setSpeed(
map.value(QStringLiteral(
"speed")).toInt());
114 if (
map.contains(QStringLiteral(
"heading"))) {
115 location->setHeading(
map.value(QStringLiteral(
"heading")).toInt());
117 if (
map.contains(QStringLiteral(
"altitude"))) {
118 location->setAltitude(
map.value(QStringLiteral(
"altitude")).toInt());
120 if (
map.contains(QStringLiteral(
"altitudeAccuracy"))) {
121 location->setAltitudeAccuracy(
map.value(QStringLiteral(
"altitudeAccuracy")).toInt());
129 return QStringLiteral(
"1");
134 QUrl url(Private::GoogleApisUrl);
135 url.
setPath(Private::CurrentLocationBasePath);
137 if (granularity == Latitude::City) {
138 query.addQueryItem(QStringLiteral(
"granularity"), QStringLiteral(
"city"));
139 }
else if (granularity == Latitude::Best) {
140 query.addQueryItem(QStringLiteral(
"granularity"), QStringLiteral(
"best"));
149 QUrl url(Private::GoogleApisUrl);
150 url.
setPath(Private::CurrentLocationBasePath);
156 QUrl url(Private::GoogleApisUrl);
157 url.
setPath(Private::CurrentLocationBasePath);
161QUrl locationHistoryUrl(
const Latitude::Granularity granularity,
const int maxResults,
const qlonglong maxTime,
const qlonglong minTime)
163 QUrl url(Private::GoogleApisUrl);
164 url.
setPath(Private::LocationBasePath);
166 if (granularity == Latitude::City) {
167 query.addQueryItem(QStringLiteral(
"granularity"), QStringLiteral(
"city"));
168 }
else if (granularity == Latitude::Best) {
169 query.addQueryItem(QStringLiteral(
"granularity"), QStringLiteral(
"best"));
172 if (maxResults > 0) {
173 query.addQueryItem(QStringLiteral(
"max-results"),
QString::number(maxResults));
176 if ((maxTime > 0) && (maxTime >= minTime)) {
177 query.addQueryItem(QStringLiteral(
"max-time"),
QString::number(maxTime));
180 if ((minTime > 0) && (minTime <= maxTime)) {
181 query.addQueryItem(QStringLiteral(
"min-time"),
QString::number(minTime));
190 QUrl url(Private::GoogleApisUrl);
193 if (granularity == Latitude::City) {
194 query.addQueryItem(QStringLiteral(
"granularity"), QStringLiteral(
"city"));
195 }
else if (granularity == Latitude::Best) {
196 query.addQueryItem(QStringLiteral(
"granularity"), QStringLiteral(
"best"));
205 QUrl url(Private::GoogleApisUrl);
206 url.
setPath(Private::LocationBasePath);
213 QUrl url(Private::GoogleApisUrl);
214 url.
setPath(Private::LocationBasePath);
Structure to store additional information about a feed.
Represents a single record about geographical location provided by Google Latitude service.
Base class for all objects.
QString APIVersion()
Supported version of API.
QUrl deleteLocationUrl(const qlonglong id)
Returns URL to delete a specific location.
ObjectsList parseLocationJSONFeed(const QByteArray &jsonFeed, FeedData &feedData)
Parses a JSON feed into list of Locations.
QUrl deleteCurrentLocationUrl()
Returns URL for deleting user's current location.
QUrl retrieveCurrentLocationUrl(const Latitude::Granularity granularity)
Returns URL for fetch current user's location.
QByteArray locationToJSON(const LocationPtr &location)
Serializes a Location object to JSON.
QUrl retrieveLocationUrl(const qlonglong id, const Latitude::Granularity granularity)
URL for fetching a specific location.
QUrl locationHistoryUrl(const Latitude::Granularity granularity, const int maxResults, const qlonglong maxTime, const qlonglong minTime)
Returns URL for fetching history of user's locations.
QUrl insertCurrentLocationUrl()
Returns URL for uploading user's current location.
LocationPtr JSONToLocation(const QByteArray &jsonData)
Parses JSON data into a Location object.
QUrl insertLocationUrl()
Returns URL for uploading a location.
A job to fetch a single map tile described by a StaticMapUrl.
QVariant location(const QVariant &res)
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonDocument fromVariant(const QVariant &variant)
bool isNull() const const
QByteArray toJson(JsonFormat format) const const
QVariant toVariant() const const
void reserve(qsizetype size)
QString number(double n, char format, int precision)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
void setPath(const QString &path, ParsingMode mode)
void setQuery(const QString &query, ParsingMode mode)
QMap< QString, QVariant > toMap() const const