getRoute

fun getRoute(origin: LatLng, destination: LatLng, mode: TransitMode? = null, language: String? = null, units: UnitSystem? = null, alternatives: Boolean? = null, waypoints: String? = null, method: Method? = null, details: Details? = null, avoid: String? = null): List<DistanceRouteElementsResponse>

Route Get distance, duration and path (as a polyline) for a pair of origin and destination, based on the recommended route between those two points for a specified travel mode.

Return

DistanceRouteResponse

Parameters

origin

The starting point. It should be supplied in the form of latitude/longitude coordinates. Ensure that no space exists between the latitude and longitude values.

destination

The ending point for the route. It should be supplied in the form of latitude/longitude coordinates. Ensure that no space exists between the latitude and longitude values.

mode

Specifies the mode of transport to use when calculating distance (optional)

language

The language code, indicating in which language the results should be returned, if possible. If language is not supplied, the Distance API service will use the navigator language or “en”. (optional)

units

Specifies the unit system parameter to use when expressing distance as text. Two different units supported: * `metric` (default) returns distances in kilometers and meters * `imperial` returns distances in miles and feet (optional)

alternatives

Specifies if alternative routes should be returned. default is `false`. Depending on the calculated route, alternatives may not be provided. `alternatives` and `waypoints` can not be used at the same time. (optional)

waypoints

A list of points by which the route should pass (route response is divided into legs, one leg corresponding to a route between two waypoints). Waypoints should be separated by | character. Optionally, you may pass `optimize:true` as the first argument within the waypoints parameter. This way the provided route is optimized by rearranging the waypoints in a more efficient order based on distance or time according to the method parameter. The route start point and end point order is not changed, their position is considered fixed. `alternatives` and `waypoints` can not be used at the same time. (optional)

method

Specifies the method to compute the route between the start point and the end point: - `time`: fastest route (default) - `distance`: shortest route (optional)

details

Specifies if maneuver instructions should be returned (roadbook). Valid values are `none` and `full` (default is `none`) (optional)

avoid

The list of features that you want to avoid. Valid values are `tolls`, `highways`, `ferries` or polygons coordinates whose vertex latlng are separated by a semicolon. To add multiple polygons, separate them with the `|` character. (optional)

Throws

If the request is not correctly configured

Rethrows the OkHttp execute method exception

If the API returns an informational or redirection response

ClientException

If the API returns a client error response

ServerException

If the API returns a server error response