convert_route

To export a line in the Encoded Polyline format to a KML or KMZ file, use the exchange/convert_route method. Usually, it’s a route built with the gis_get_route_via_waypoints request, but you can also encode any other set of coordinates.

Endpoint

Copied!
svc=exchange/convert_route&params={
  "route": <text>,
  "fileName": <text>,
  "compress": <bool>,
  "route_name": <text>,
  "route_description": <text>,
  "color": <int>,
  "width": <int>
}

Parameters

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

Parameter Description
route* Route line encoded with the Encoded Polyline Algorithm (precision 1e5). You can get it from the points field of the gis_get_route_via_waypoints response.
fileName* File name without an extension. If you specify an empty string, the file is named Routes.
compress* Specify 1 to get a KMZ file (a compressed KML file), or 0 to get a KML file.
route_name Route name. By default, Route.
route_description Route description. By default, empty.
color Line color as an integer. It’s written to the file as 8 hexadecimal digits in the KML order: alpha (opacity), blue, green, red. For example, 4278190335 (0xFF0000FF) is opaque red. By default, dd0066ff.
width Line width in pixels. By default, 10.

Response

If the request is completed successfully, a KML or KMZ file is returned. The route is saved as a line (LineString) in a single placemark. The altitude of all points is 0. For the file structure, see the example.

If the route value can’t be decoded, the file is still returned, but it contains no coordinates.

If the request fails, an error code is returned.

Error codes

Error code Description
1 Invalid or obsolete request SID.
3 The route parameter is empty.
4 One of the following errors:
  • parameter validation error,
  • failed to create a directory for temporary results.
6 One of the following errors:
  • failed to fetch the current user,
  • error processing XML,
  • error compressing the file.

Example

In this example, a route with three points is exported to an uncompressed KML file. The line color and width aren’t specified, so the default values are used.

Request:

Copied!
svc=exchange/convert_route&params={
  "route": "_p~iF~ps|U_ulLnnqC_mqNvxq`@",
  "fileName": "route_export",
  "compress": 0,
  "route_name": "Delivery route"
}

Response (contents of the route_export.kml file):

Copied!
<?xml version="1.0" encoding="utf-8"?>

<kml>
	<Document>
		<name>
			route_export
		</name>
		<Placemark>
			<name>
				Delivery route
			</name>
			<description/>
			<Style>
				<LineStyle>
					<color>
						dd0066ff
					</color>
					<width>
						10
					</width>
				</LineStyle>
			</Style>
			<LineString>
				<coordinates>
					-120.200000,38.500000,0
-120.950000,40.700000,0
-126.453000,43.252000,0

				</coordinates>
			</LineString>
		</Placemark>
	</Document>
</kml>

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