gis_get_route_via_waypoints

To build a route from the origin to the destination through intermediate points (waypoints), use the gis_get_route_via_waypoints request. The request can also change the order of the waypoints to get the optimal route.

Endpoint

Copied!
<gis_routing>/gis_get_route_via_waypoints?gis_sid=<text>&search_provider=<text>&data={
  "origin": {
    "lat": <double>,
    "lon": <double>
  },
  "destination": {
    "lat": <double>,
    "lon": <double>
  },
  "waypoints": [
    {
      "lat": <double>,
      "lon": <double>
    },
    ...
  ],
  "flags": <uint>,
  "params": {
    ...
  },
  "optimizeParams": {
    "enable": <bool>,
    "useProviderOptimize": <bool>,
    "fixOrigin": <bool>,
    "fixDestination": <bool>,
    "matrixProvider": <text>,
    ...
  }
}

The <gis_routing> is the GIS routing URL returned in the gis_routing key of the token/login response.

Parameters

The required parameters are marked with an asterisk (*).

Parameter Description
gis_sid* Session ID for the GIS services. It is returned in the gis_sid key of the token/login response.
search_provider Routing provider:
  • empty or webgis — Gurtam Maps;
  • google — Google;
  • yandex — Yandex;
  • sygic — Sygic;
  • here — HERE;
  • trimble — Trimble.
To use an external provider, the corresponding service must be enabled for the account and the map key of the provider must be specified. Each request is counted towards the limit of the service.
data* JSON object with the route parameters. See the description below.

The data object can contain the following keys:

Key Description
origin* Coordinates of the starting point of the route: latitude (lat) and longitude (lon).
destination* Coordinates of the final point of the route: latitude (lat) and longitude (lon).
waypoints Array of the intermediate points in the order in which the route must pass them. Each point contains latitude (lat) and longitude (lon). Gurtam Maps supports up to 1000 waypoints.
flags Response flags. See the Flags section.
params Settings of the external routing provider. See the Provider settings section. Gurtam Maps ignores this object.
optimizeParams Settings of the waypoint order optimization. See the Optimization section. If the object isn’t specified, the route passes the waypoints in the specified order.

Flags

Flag Description
0x1 Add the sections array to the response. It contains the parameters of each route section between two neighboring points.
0x2 Return the route inside the routes array. This flag is required to get alternative routes from an external provider.

Provider settings

The keys of the params object depend on the provider. The values are passed to the provider API, so see the documentation of the provider for the possible values.

Provider Keys of the params object
Google alternatives, departure_time, mode, avoid, traffic_model, transit_mode, transit_routing_preference.
Yandex alternatives, departure_time, avoid_tolls, mode. If mode is truck, also weight, axle_weight, max_weight, height, width, length, payload, eco_class, has_trailer.
Sygic compute_alternatives, avoid, traffic, vehicle_type, route_computing, speed_profiles, departure_time, prefer_right_turn, total_weight, axle_weight, total_length, width, height, trailers, vehicle_axles, trailer_axles, general_hazard, water_hazard, tunnel.
HERE alternatives (number of alternative routes), transportMode (car by default), routingMode (fast by default), departureTime, arrivalTime, exclude, lang, TrafficMode, avoid (object), truck (object, used if transportMode is truck).
Trimble Options (object), ReportingOptions (object), EstimatedTimeOptions (object), DateAndTime (object).

To get alternative routes, specify the 0x2 flag. Otherwise, the ALTERNATIVES_ERROR error is returned.

If you specify departure_time for Google, the route duration is calculated with traffic taken into account.

Optimization

If optimization is enabled, the system changes the order of the waypoints to make the route optimal. To enable optimization, specify the following keys in the optimizeParams object:

Key Description
enable Enable optimization: true or 1 — yes, false or 0 — no.
useProviderOptimize Use the optimization of the provider instead of the Wialon optimization. It is supported only by Google. For Google, the route can contain up to 27 points, including the origin and destination. Provider optimization can’t be used together with alternatives or departure_time. If you specify this key for other providers, the route is built without optimization.
fixOrigin Keep the origin as the first point of the route: true (default) or false. If the value is false, the origin can be moved to another position.
fixDestination Keep the destination as the last point of the route: true (default) or false. If the value is false, the destination can be moved to another position.
matrixProvider Provider used to calculate the distances between the points for the Wialon optimization:
  • empty — the provider from the search_provider parameter if the map key for the distance matrix is specified for it, otherwise Gurtam Maps;
  • webgis — Gurtam Maps;
  • name of an external provider, for example, google;
  • disable — the distances aren’t calculated by roads.

If there are fewer than two points whose position can change, the order of the points remains the same.

The optimization takes up to 265 seconds.

Advanced optimizer settings

The optimizeParams object can also contain the settings of the Wialon optimizer. They aren’t used if useProviderOptimize is enabled. Specify numeric values as numbers, not strings.

The optimizer chooses the order of points with the lowest total cost. The cost of a route depends on its length and travel time:

Key Description
penalty_unit_driving_mileage Cost of one meter of the route. Default value: 2.
penalty_unit_driving_duration Cost of one second of travel. Default value: 1.
penalty_unit_additional_duration Cost of one second of the time spent on each stop. The optimizer adds 110 seconds for each move between points that are more than 55 meters apart. Default value: 1.
coef_unit_driving_mileage, coef_unit_driving_duration, coef_unit_additional_duration Multipliers for the corresponding penalty_* values.
penalties_profile Set of multipliers for the costs:
  • balanced — the costs aren’t changed (default);
  • fast — the cost of the route length is reduced by half;
  • cost_effective — the costs of late arrival and unit use are changed. They don’t affect this request.

With the default values, 1 km of the route costs 2000 and 1 minute of travel costs 60, so the optimizer prefers the shortest route. To prefer the fastest route, decrease penalty_unit_driving_mileage or increase penalty_unit_driving_duration.

The travel time between points is calculated with the following settings:

Key Description
direct_speed Speed in km/h used to calculate the travel time by straight-line distance. It is used if the distance by roads isn’t available, for example, if matrixProvider is disable. Default value: 60.
city_jams Traffic coefficient for city roads, that is, sections with an average speed up to 60 km/h. The travel time is divided by this value, so values less than 1 increase the travel time. Default value: 1. If city_jams and country_jams are equal, city_jams is used for all sections.
country_jams Traffic coefficient for sections with an average speed over 60 km/h. Default value: 1.

The calculation is controlled by the following settings:

Key Description
optimizer_mode Optimization algorithm. If the key isn’t specified, the default algorithm is used. The ga value enables the outdated genetic algorithm.
sa_maxiter Maximum number of iterations of the default algorithm. Default value: 125000000000.
sa_calcwindow Number of iterations without improvement after which the default algorithm stops. Possible values: from 1 to 99999999. Default value: 3000000.
sa_threads Number of calculation threads of the default algorithm: 1 (default) or 2.
ga_popsize, ga_maxiter, ga_eliterate, ga_mutationrate, ga_calcwindow Settings of the genetic algorithm: population size (default 3412), maximum number of iterations (5000), elite rate (0.05), mutation rate (0.25), and the number of iterations without improvement after which the calculation stops (100).
optimize_off Keep the order of the points: 1 — yes, 0 — no (default). The outdated name ga_off is also supported.

Response

If the request is completed successfully, the response is returned in the following format:

Copied!
{
  "start_location": {      /* Starting point of the route. */
    "lat": <double>,       /* Latitude. */
    "lon": <double>        /* Longitude. */
  },
  "end_location": {        /* Final point of the route. */
    "lat": <double>,
    "lon": <double>
  },
  "points": <text>,        /* Route line encoded with the Encoded Polyline Algorithm (precision 1e5). */
  "distance": {            /* Route length. */
    "text": <text>,        /* Formatted value, for example, "12.35 km". */
    "value": <double>      /* Value in meters. */
  },
  "duration": {            /* Travel time. */
    "text": <text>,        /* Formatted value. */
    "value": <uint>        /* Value in seconds. */
  },
  "sections": [            /* Route sections between neighboring points. Returned with the 0x1 flag. */
    {
      "status": <text>,    /* Section status: "OK" or "NOT FOUND". */
      "start_location": {...},
      "end_location": {...},
      "points": <text>,
      "distance": {...},
      "duration": {...}
    },
    ...
  ],
  "point_order": [<uint>], /* Order of the points in the optimized route. Returned if optimization is enabled. */
  "status": <text>         /* Route status: "OK" or "NOT FOUND". */
}

If the route can’t be built, for example, a point is too far from the roads, the status key has the NOT FOUND value. Gurtam Maps returns only this key in this case.

The point_order array contains the indexes of the points in the order in which the route passes them. The origin has index 0, the waypoints have indexes from 1 in the order in which they are specified in the request, and the destination has the last index.

With the 0x2 flag, the route keys except point_order and status are returned inside the routes array:

Copied!
{
  "routes": [
    {
      "start_location": {...},
      "end_location": {...},
      "points": <text>,
      "distance": {...},
      "duration": {...},
      "sections": [...]
    },
    ...
  ],
  "point_order": [<uint>],
  "status": <text>
}

The routes array contains several routes if alternative routes are requested from the provider. Otherwise, it contains one route.

The response from external providers has the following differences:

  • The distance and duration objects contain only the value key.
  • The start_location and end_location keys of the route contain the coordinates specified in the request. Gurtam Maps returns the coordinates of the nearest points on the roads.

Error codes

If the request fails, an error is returned in the following format:

Copied!
{
  "error": <uint>,           /* Error code. */
  "reason": <text>,          /* Error reason. */
  "details": {
    "description": <text>    /* Error description. Returned not for all errors. */
  }
}
Error code Reason Description
1 INVALID_SESSION Invalid session.
4 PARAMS_NOT_FOUND, VALIDATE_PARAMS_ERROR The data parameter isn’t specified, or the route parameters are wrong. For example, the coordinates are out of range or there are more than 1000 waypoints for Gurtam Maps.
4 ALTERNATIVES_ERROR Alternative routes are requested without the 0x2 flag.
4 OPTIMIZE_ERROR, MAX_WAYPOINTS_EXCEEDED Google optimization is requested together with alternative routes or traffic, or the route contains more than 27 points.
4 INVALID_API_KEY The map key of the external provider isn’t specified.
6 UNKNOWN_ERROR The route can’t be built because of an internal error.
6 OPTIMIZE_ERROR The order of the waypoints can’t be optimized.
6 PROVIDER_RESPONSE_ERROR, RESPONSE_PARSING_ERROR The external provider returned an error or a response that can’t be processed. For PROVIDER_RESPONSE_ERROR, the details object also contains the HTTP code (provider_http_code) and the response of the provider (provider_response).
7 PROVIDER_NOT_FOUND, SERVICE_NOT_FOUND The provider is unknown or unavailable, the corresponding service isn’t enabled for the account, or the limit of the service is exceeded.

If you find a mistake in the text, please select it and press Ctrl+Enter.