const QString CLOUDMADE_AUTH_PART = "http://auth.cloudmade.com/token/";
const QString CLOUDMADE_API_KEY = "0cea0072adbf42ce823f4c78b974f12d";
-// geocode
-const QString GEOCODE = "http://maps.google.com/maps/api/geocode/json?address=";
-
-
RoutingService::RoutingService(QObject *parent)
: QObject(parent)
{
segment.setLengthCaption(list.at(4));
segment.setEarthDirection(list.at(5));
segment.setAzimuth(list.at(6).toDouble());
- if (list.count() == 8) {
+ if (list.count() == 9) {
segment.setTurnType(list.at(7));
segment.setTurnAngle(list.at(8).toDouble());
}
}
}
-void RoutingService::parseSearchResults(const QByteArray &jsonReply)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- const QString NO_DATA = "ZERO_RESULTS";
-
- m_searchResults.clear();
-
- QJson::Parser parser;
- bool ok;
- QVariantMap result = parser.parse (jsonReply, &ok).toMap();
- if (!ok) {
- emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
- return;
- } else {
- if(result.value("status") != NO_DATA) {
- foreach(QVariant hitVariant, result["results"].toList()) {
- Location location;
- QMap<QString, QVariant> hitMap = hitVariant.toMap();
-
- location.setFormattedAddress(hitMap["formatted_address"].toString());
-
- QVariant geometryVariant = hitMap["geometry"];
- QMap<QString, QVariant> geometryMap = geometryVariant.toMap();
- QVariant locationVariant = geometryMap["location"];
- QMap<QString, QVariant> locationMap = locationVariant.toMap();
- location.setCoordinates(locationMap["lat"].toDouble(),
- locationMap["lng"].toDouble());
-
- QVariant boundsVariant = geometryMap["bounds"];
- QMap<QString, QVariant> boundsMap = boundsVariant.toMap();
- QVariant swVariant = boundsMap["southwest"];
- QMap<QString, QVariant> swMap = swVariant.toMap();
- location.setSWBound(swMap["lat"].toDouble(),
- swMap["lng"].toDouble());
- QVariant neVariant = boundsMap["northeast"];
- QMap<QString, QVariant> neMap = neVariant.toMap();
- location.setNEBound(neMap["lat"].toDouble(),
- neMap["lng"].toDouble());
-
- m_searchResults.append(location);
- }
-
- emit locationDataParsed(m_searchResults);
- }
- }
-}
-
void RoutingService::requestAuthorizationToken()
{
qDebug() << __PRETTY_FUNCTION__;
qDebug() << __PRETTY_FUNCTION__;
QByteArray replyArray = reply->readAll();
- qDebug() << "Reply from: " << reply->url() << "reply " << replyArray;
if (reply->error()) {
emit error(ErrorContext::NETWORK, reply->error());
m_pendingRequest.append(m_token);
sendRequest(m_pendingRequest);
m_pendingRequest.clear();
- } else if(reply->url().toString().contains(GEOCODE)) {
- parseSearchResults(replyArray);
} else {
parseRouteData(replyArray);
}
reply->deleteLater();
}
-void RoutingService::requestLocation(const QString &location)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- const QString urlEnd = "&sensor=false";
-
- QString url = GEOCODE;
- url.append(location);
- url.append(urlEnd);
-
- sendRequest(url);
-}
-
void RoutingService::requestRoute(const GeoCoordinate &from, const GeoCoordinate &to)
{
qDebug() << __PRETTY_FUNCTION__;