Ejemplo n.º 1
0
QStringList QGeoRoutingManagerEngineNokia::calculateRouteRequestString(const QGeoRouteRequest &request)
{
    bool supported = checkEngineSupport(request, request.travelModes());

    if (!supported)
        return QStringList();
    QStringList requests;

    QString baseRequest = QStringLiteral("http://");
    baseRequest += m_uriProvider->getCurrentHost();
    baseRequest += QStringLiteral("/routing/7.2/calculateroute.xml");

    baseRequest += QStringLiteral("?alternatives=");
    baseRequest += QString::number(request.numberAlternativeRoutes());

    if (!m_appId.isEmpty() && !m_token.isEmpty()) {
        baseRequest += QStringLiteral("&app_id=");
        baseRequest += m_appId;
        baseRequest += QStringLiteral("&token=");
        baseRequest += m_token;
    }

    int numWaypoints = request.waypoints().size();
    if (numWaypoints < 2)
        return QStringList();

    for (int i = 0;i < numWaypoints;++i) {
        baseRequest += QStringLiteral("&waypoint");
        baseRequest += QString::number(i);
        baseRequest += QStringLiteral("=geo!");
        baseRequest += trimDouble(request.waypoints().at(i).latitude());
        baseRequest += ',';
        baseRequest += trimDouble(request.waypoints().at(i).longitude());
    }

    QGeoRouteRequest::RouteOptimizations optimization = request.routeOptimization();

    QStringList types;
    if (optimization.testFlag(QGeoRouteRequest::ShortestRoute))
        types.append("shortest");
    if (optimization.testFlag(QGeoRouteRequest::FastestRoute))
        types.append("fastest");

    foreach (const QString &optimization, types) {
        QString requestString = baseRequest;
        requestString += modesRequestString(request, request.travelModes(), optimization);
        requestString += routeRequestString(request);
        requests << requestString;
    }
QString QGeoRoutingManagerEngineNokia::calculateRouteRequestString(const QGeoRouteRequest &request)
{
    bool supported = checkEngineSupport(request, request.travelModes());

    if ((request.numberAlternativeRoutes() != 0) && !supportsAlternativeRoutes())
        supported = false;

    if (!supported)
        return "";

    QString requestString = "http://";
    requestString += m_host;
    requestString += "/routing/6.2/calculateroute.xml?referer=" + m_referer;

    if (!m_token.isNull())
        requestString += "&token=" + m_token;

    int numWaypoints = request.waypoints().size();
    if (numWaypoints < 2)
        return "";

    for (int i = 0;i < numWaypoints;++i) {
        requestString += "&waypoint";
        requestString += QString::number(i);
        requestString += "=";
        requestString += trimDouble(request.waypoints().at(i).latitude());
        requestString += ",";
        requestString += trimDouble(request.waypoints().at(i).longitude());
    }

    requestString += modesRequestString(request, request.travelModes());

    requestString += "&alternatives=";
    requestString += QString::number(request.numberAlternativeRoutes());

    requestString += routeRequestString(request);

    return requestString;
}
QString QGeoRoutingManagerEngineNokia::updateRouteRequestString(const QGeoRoute &route, const QGeoCoordinate &position)
{
    if (!checkEngineSupport(route.request(), route.travelMode()))
        return "";

    QString requestString = "http://";
    requestString += m_host;
    requestString += "/routing/6.2/getroute.xml";

    requestString += "?routeid=";
    requestString += route.routeId();

    requestString += "&pos=";
    requestString += QString::number(position.latitude());
    requestString += ",";
    requestString += QString::number(position.longitude());

    requestString += modesRequestString(route.request(), route.travelMode());

    requestString += routeRequestString(route.request());

    return requestString;
}