Skip to content

Routing API

InvalidCredentialsError

Invalid Credentials Error Type.

This error is returned if the specified token was invalid or no contract could be found for this token.

InvalidInputDataError

Invalid Input Data Error Type.

This error is returned if the specified request parameters contain invalid data, such as due to wrong parameter syntax or invalid parameter combinations.

LinkIdNotFoundError

Link Not Found Error Type.

This error indicates that a link ID passed as input parameter could not be found in the underlying map data.

NoRouteFoundError

No Route Found Error Type.

This error indicates that no route could be constructed based on the input parameter.

RouteNotReconstructedError

Route Not Reconstructed Error Type.

This error indicates that the RouteId is invalid (RouteId can not be decoded into valid data) or route failed to be reconstructed from the RouteId. In every case a mitigation is to re-run CalculateRoute request to acquire a new proper RouteId.

RoutingApi

A python interface into the HERE Routing API

__init__(self, api_key=None, timeout=None) special

Returns a RoutingApi instance.

Parameters:

Name Type Description Default
api_key str

API key taken from HERE Developer Portal.

None
timeout int

Timeout limit for requests.

None
Source code in herepy/routing_api.py
def __init__(self, api_key: str = None, timeout: int = None):
    """Returns a RoutingApi instance.
    Args:
      api_key (str):
        API key taken from HERE Developer Portal.
      timeout (int):
        Timeout limit for requests.
    """

    super(RoutingApi, self).__init__(api_key, timeout)

async_matrix(self, token, origins, destinations, matrix_type=<MatrixRoutingType.world: 'world'>, center=None, radius=None, profile=None, departure=None, routing_mode=None, transport_mode=None, avoid=None, truck=None, matrix_attributes=None)

Async request a matrix of route summaries between M starts and N destinations.

Parameters:

Name Type Description Default
token str

Bearer token required for async calls. This is the only working solution for now. How to create a bearer token: https://developer.here.com/documentation/identity-access-management/dev_guide/topics/sdk.html#step-1-register-your-application https://developer.here.com/documentation/identity-access-management/dev_guide/topics/postman.html

required
origins Union[List[float], str]

List of lists of coordinates [lat,long] of start waypoints. or list of string with the location names.

required
destinations Union[List[float], str]

List of lists of coordinates [lat,long] of destination waypoints. or list of string with the location names.

required
matrix_type MatrixRoutingType

Routing type used in definition of a region in which the matrix will be calculated.

<MatrixRoutingType.world: 'world'>
center Optional[List[float]]

Center of region definition, latitude and longitude.

None
radius Optional[int]

Center of region definition.

None
profile Optional[herepy.here_enum.MatrixRoutingProfile]

A profile ID enables the calculation of matrices with routes of arbitrary length.

None
departure str

time when travel is expected to start, e.g.: '2013-07-04T17:00:00+02'

None
routing_mode Optional[herepy.here_enum.MatrixRoutingMode]

Route mode used in optimization of route calculation.

None
transport_mode Optional[herepy.here_enum.MatrixRoutingTransportMode]

Depending on the transport mode special constraints, speed attributes and weights are taken into account during route calculation.

None
avoid Optional[herepy.objects.Avoid]

Avoid routes that violate these properties.

None
truck Optional[herepy.objects.Truck]

Different truck options to use during route calculation when transportMode = truck.

None
matrix_attributes Optional[List[herepy.here_enum.MatrixSummaryAttribute]]

List of MatrixSummaryAttribute enums.

None

Returns:

Type Description
Optional[herepy.models.RoutingMatrixResponse]

RoutingMatrixResponse.

Exceptions:

Type Description
HEREError

If an error is received from the server.

Source code in herepy/routing_api.py
def async_matrix(
    self,
    token: str,
    origins: Union[List[float], str],
    destinations: Union[List[float], str],
    matrix_type: MatrixRoutingType = MatrixRoutingType.world,
    center: Optional[List[float]] = None,
    radius: Optional[int] = None,
    profile: Optional[MatrixRoutingProfile] = None,
    departure: str = None,
    routing_mode: Optional[MatrixRoutingMode] = None,
    transport_mode: Optional[MatrixRoutingTransportMode] = None,
    avoid: Optional[Avoid] = None,
    truck: Optional[Truck] = None,
    matrix_attributes: Optional[List[MatrixSummaryAttribute]] = None,
) -> Optional[RoutingMatrixResponse]:
    """Async request a matrix of route summaries between M starts and N destinations.
    Args:
      token (str):
        Bearer token required for async calls. This is the only working solution for now.
        How to create a bearer token:
        https://developer.here.com/documentation/identity-access-management/dev_guide/topics/sdk.html#step-1-register-your-application
        https://developer.here.com/documentation/identity-access-management/dev_guide/topics/postman.html
      origins (List):
        List of lists of coordinates [lat,long] of start waypoints.
        or list of string with the location names.
      destinations (List):
        List of lists of coordinates [lat,long] of destination waypoints.
        or list of string with the location names.
      matrix_type (MatrixRoutingType):
        Routing type used in definition of a region in which the matrix will be calculated.
      center (Optional[List]):
        Center of region definition, latitude and longitude.
      radius (Optional[int]):
        Center  of region definition.
      profile (Optional[MatrixRoutingProfile]):
        A profile ID enables the calculation of matrices with routes of arbitrary length.
      departure (str):
        time when travel is expected to start, e.g.: '2013-07-04T17:00:00+02'
      routing_mode (Optional[MatrixRoutingMode]):
        Route mode used in optimization of route calculation.
      transport_mode (Optional[MatrixRoutingTransportMode]):
        Depending on the transport mode special constraints, speed attributes and weights
        are taken into account during route calculation.
      avoid (Optional[Avoid]):
        Avoid routes that violate these properties.
      truck (Optional[Truck]):
        Different truck options to use during route calculation when transportMode = truck.
      matrix_attributes (List):
        List of MatrixSummaryAttribute enums.
    Returns:
      RoutingMatrixResponse.
    Raises:
      HEREError: If an error is received from the server.
    """

    query_params = {}

    request_body = self.__prepare_matrix_request_body(
        origins=origins,
        destinations=destinations,
        matrix_type=matrix_type,
        center=center,
        radius=radius,
        profile=profile,
        departure=departure,
        routing_mode=routing_mode,
        transport_mode=transport_mode,
        avoid=avoid,
        truck=truck,
        matrix_attributes=matrix_attributes,
    )

    url = Utils.build_url(self.URL_CALCULATE_MATRIX, extra_params=query_params)
    headers = {
        "Content-Type": "application/json",
        "Authorization": str.format("Bearer {0}", token),
    }
    json_data = json.dumps(request_body)
    response = requests.post(
        url, json=request_body, headers=headers, timeout=self._timeout
    )
    if response.status_code == requests.codes.ACCEPTED:
        json_data = response.json()
        print(
            "Matrix {} calculation {}".format(
                json_data["matrixId"], json_data["status"]
            )
        )
        poll_url = json_data["statusUrl"]
        headers = {"Authorization": str.format("Bearer {0}", token)}
        print("Polling matrix calculation started!")
        result = polling.poll(
            lambda: requests.get(poll_url, headers=headers),
            check_success=self.__is_correct_response,
            step=5,
            poll_forever=True,
        )
        print("Polling matrix calculation completed!")
        poll_data = result.json()
        return RoutingMatrixResponse.new_from_jsondict(poll_data)
    else:
        json_data = response.json()
        if (
            json_data.get("error") is not None
            and json_data.get("error_description") is not None
        ):
            raise HEREError(
                "Error occured on async_matrix: "
                + json_data["error"]
                + ", description: "
                + json_data["error_description"]
            )
        elif (
            json_data.get("title") is not None
            and json_data.get("cause") is not None
        ):
            raise HEREError(
                "Error occured on async_matrix: "
                + json_data["title"]
                + ", cause: "
                + json_data["cause"]
            )
        else:
            raise HEREError(
                "Error occured on async_matrix " + sys._getframe(1).f_code.co_name
            )

bicycle_route(self, waypoint_a, waypoint_b, modes=None, departure='now')

Request a bicycle route between two points

Parameters:

Name Type Description Default
waypoint_a Union[List[float], str]

List contains latitude and longitude in order or string with the location name

required
waypoint_b Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
modes List[herepy.here_enum.RouteMode]

List contains RouteMode enums.

None
departure str

Date time str in format yyyy-mm-ddThh:mm:ss. Default now.

'now'

Returns:

Type Description
Optional[herepy.models.RoutingResponse]

RoutingResponse

Source code in herepy/routing_api.py
def bicycle_route(
    self,
    waypoint_a: Union[List[float], str],
    waypoint_b: Union[List[float], str],
    modes: List[RouteMode] = None,
    departure: str = "now",
) -> Optional[RoutingResponse]:
    """Request a bicycle route between two points
    Args:
      waypoint_a:
        List contains latitude and longitude in order
        or string with the location name
      waypoint_b:
        List contains latitude and longitude in order
        or string with the location name.
      modes (List):
        List contains RouteMode enums.
      departure (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `now`.
    Returns:
      RoutingResponse
    Raises:
      HEREError"""

    if modes is None:
        modes = [RouteMode.bicycle, RouteMode.fastest]
    return self._route(waypoint_a, waypoint_b, modes, departure)

car_route(self, waypoint_a, waypoint_b, modes=None, departure='now')

Request a driving route between two points

Parameters:

Name Type Description Default
waypoint_a Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
waypoint_b Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
modes List[herepy.here_enum.RouteMode]

List contains RouteMode enums.

None
departure str

Date time str in format yyyy-mm-ddThh:mm:ss. Default now.

'now'

Returns:

Type Description
Optional[herepy.models.RoutingResponse]

RoutingResponse

Source code in herepy/routing_api.py
def car_route(
    self,
    waypoint_a: Union[List[float], str],
    waypoint_b: Union[List[float], str],
    modes: List[RouteMode] = None,
    departure: str = "now",
) -> Optional[RoutingResponse]:
    """Request a driving route between two points
    Args:
      waypoint_a (List):
        List contains latitude and longitude in order
        or string with the location name.
      waypoint_b (List):
        List contains latitude and longitude in order
        or string with the location name.
      modes (List):
        List contains RouteMode enums.
      departure (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `now`.
    Returns:
      RoutingResponse
    Raises:
      HEREError"""

    if modes is None:
        modes = [RouteMode.car, RouteMode.fastest]
    return self._route(waypoint_a, waypoint_b, modes, departure)

intermediate_route(self, waypoint_a, waypoint_b, waypoint_c, modes=None, departure='now')

Request a intermediate route from three points

Parameters:

Name Type Description Default
waypoint_a Union[List[float], str]

Starting List contains latitude and longitude in order or string with the location name.

required
waypoint_b Union[List[float], str]

Intermediate List contains latitude and longitude in order or string with the location name.

required
waypoint_c Union[List[float], str]

Last List contains latitude and longitude in order or string with the location name.

required
modes List[herepy.here_enum.RouteMode]

List contains RouteMode enums.

None
departure str

Date time str in format yyyy-mm-ddThh:mm:ss. Default now.

'now'

Returns:

Type Description
Optional[herepy.models.RoutingResponse]

RoutingResponse

Source code in herepy/routing_api.py
def intermediate_route(
    self,
    waypoint_a: Union[List[float], str],
    waypoint_b: Union[List[float], str],
    waypoint_c: Union[List[float], str],
    modes: List[RouteMode] = None,
    departure: str = "now",
) -> Optional[RoutingResponse]:
    """Request a intermediate route from three points
    Args:
      waypoint_a (List):
        Starting List contains latitude and longitude in order
        or string with the location name.
      waypoint_b (List):
        Intermediate List contains latitude and longitude in order
        or string with the location name.
      waypoint_c (List):
        Last List contains latitude and longitude in order
        or string with the location name.
      modes (List):
        List contains RouteMode enums.
      departure (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `now`.
    Returns:
      RoutingResponse
    Raises:
      HEREError"""

    if modes is None:
        modes = [RouteMode.car, RouteMode.fastest]
    return self._route(waypoint_a, waypoint_b, modes, departure)

location_near_motorway(self, waypoint_a, waypoint_b, modes=None, departure='now')

Calculates the fastest car route between two location

Parameters:

Name Type Description Default
waypoint_a Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
waypoint_b Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
modes List[herepy.here_enum.RouteMode]

List contains RouteMode enums.

None
departure str

Date time str in format yyyy-mm-ddThh:mm:ss. Default now.

'now'

Returns:

Type Description
Optional[herepy.models.RoutingResponse]

RoutingResponse

Source code in herepy/routing_api.py
def location_near_motorway(
    self,
    waypoint_a: Union[List[float], str],
    waypoint_b: Union[List[float], str],
    modes: List[RouteMode] = None,
    departure: str = "now",
) -> Optional[RoutingResponse]:
    """Calculates the fastest car route between two location
    Args:
      waypoint_a (List):
        List contains latitude and longitude in order
        or string with the location name.
      waypoint_b (List):
        List contains latitude and longitude in order
        or string with the location name.
      modes (List):
        List contains RouteMode enums.
      departure (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `now`.
    Returns:
      RoutingResponse
    Raises:
      HEREError"""

    if modes is None:
        modes = [RouteMode.car, RouteMode.fastest]
    return self._route(waypoint_a, waypoint_b, modes, departure)

pedastrian_route(self, waypoint_a, waypoint_b, modes=None, departure='now')

Request a pedastrian route between two points

Parameters:

Name Type Description Default
waypoint_a Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
waypoint_b Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
modes List[herepy.here_enum.RouteMode]

List contains RouteMode enums.

None
departure str

Date time str in format yyyy-mm-ddThh:mm:ss. Default now.

'now'

Returns:

Type Description
Optional[herepy.models.RoutingResponse]

RoutingResponse

Source code in herepy/routing_api.py
def pedastrian_route(
    self,
    waypoint_a: Union[List[float], str],
    waypoint_b: Union[List[float], str],
    modes: List[RouteMode] = None,
    departure: str = "now",
) -> Optional[RoutingResponse]:
    """Request a pedastrian route between two points
    Args:
      waypoint_a (List):
        List contains latitude and longitude in order
        or string with the location name.
      waypoint_b (List):
        List contains latitude and longitude in order
        or string with the location name.
      modes (List):
        List contains RouteMode enums.
      departure (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `now`.
    Returns:
      RoutingResponse
    Raises:
      HEREError"""

    if modes is None:
        modes = [RouteMode.pedestrian, RouteMode.fastest]
    return self._route(waypoint_a, waypoint_b, modes, departure)

public_transport(self, waypoint_a, waypoint_b, combine_change, modes=None, departure='now')

Request a public transport route between two points

Parameters:

Name Type Description Default
waypoint_a Union[List[float], str]

Starting List contains latitude and longitude in order or string with the location name.

required
waypoint_b Union[List[float], str]

Intermediate List contains latitude and longitude in order or string with the location name.

required
combine_change bool

Enables the change manuever in the route response, which indicates a public transit line change.

required
modes List[herepy.here_enum.RouteMode]

List contains RouteMode enums.

None
departure str

Date time str in format yyyy-mm-ddThh:mm:ss. Default now.

'now'

Returns:

Type Description
Optional[herepy.models.RoutingResponse]

RoutingResponse

Source code in herepy/routing_api.py
def public_transport(
    self,
    waypoint_a: Union[List[float], str],
    waypoint_b: Union[List[float], str],
    combine_change: bool,
    modes: List[RouteMode] = None,
    departure="now",
) -> Optional[RoutingResponse]:
    """Request a public transport route between two points
    Args:
      waypoint_a (List):
        Starting List contains latitude and longitude in order
        or string with the location name.
      waypoint_b (List):
        Intermediate List contains latitude and longitude in order
        or string with the location name.
      combine_change (bool):
        Enables the change manuever in the route response, which
        indicates a public transit line change.
      modes (List):
        List contains RouteMode enums.
      departure (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `now`.
    Returns:
      RoutingResponse
    Raises:
      HEREError"""

    if modes is None:
        modes = [RouteMode.publicTransport, RouteMode.fastest]
    return self._route(waypoint_a, waypoint_b, modes, departure)

public_transport_timetable(self, waypoint_a, waypoint_b, combine_change, modes=None, departure=None, arrival=None)

Request a public transport route between two points based on timetables

Parameters:

Name Type Description Default
waypoint_a Union[List[float], str]

Starting List contains latitude and longitude in order or string with the location name.

required
waypoint_b Union[List[float], str]

Intermediate List contains latitude and longitude in order or string with the location name.

required
combine_change bool

Enables the change manuever in the route response, which indicates a public transit line change.

required
modes List[herepy.here_enum.RouteMode]

List contains RouteMode enums.

None
departure str

Date time str in format yyyy-mm-ddThh:mm:ss. Default None.

None
arrival str

Date time str in format yyyy-mm-ddThh:mm:ss. Default None.

None

Returns:

Type Description
Optional[herepy.models.RoutingResponse]

RoutingResponse

Source code in herepy/routing_api.py
def public_transport_timetable(
    self,
    waypoint_a: Union[List[float], str],
    waypoint_b: Union[List[float], str],
    combine_change: bool,
    modes: List[RouteMode] = None,
    departure: str = None,
    arrival: str = None,
) -> Optional[RoutingResponse]:
    """Request a public transport route between two points based on timetables
    Args:
      waypoint_a (List):
        Starting List contains latitude and longitude in order
        or string with the location name.
      waypoint_b (List):
        Intermediate List contains latitude and longitude in order
        or string with the location name.
      combine_change (bool):
        Enables the change manuever in the route response, which
        indicates a public transit line change.
      modes (List):
        List contains RouteMode enums.
      departure (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `None`.
      arrival (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `None`.
    Returns:
      RoutingResponse
    Raises:
      HEREError"""

    if modes is None:
        modes = [RouteMode.publicTransportTimeTable, RouteMode.fastest]
    return self._route(waypoint_a, waypoint_b, modes, departure, arrival)

route_v8(self, transport_mode, origin, destination, via=None, departure_time=None, routing_mode=<RoutingMode.fast: 'fast'>, alternatives=None, avoid=None, exclude=None, units=None, lang=None, return_fields=[<RoutingApiReturnField.polyline: 'polyline'>], span_fields=None, truck=None, scooter=None, headers=None)

Calculates the route between given origin and destination.

Parameters:

Name Type Description Default
transport_mode RoutingTransportMode

Mode of transport to be used for the calculation of the route.

required
origin Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
destination Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
via Optional[List[List[float]]]

Locations defining via waypoints. Locations between origin and destination.

None
departure_time Optional[str]

Specifies the time of departure as defined by either date-time or full-date T partial-time in RFC 3339, section 5.6 (for example, 2019-06-24T01:23:45).

None
routing_mode RoutingMode

Specifies which optimization is applied during route calculation, fast as default value.

<RoutingMode.fast: 'fast'>
alternatives Optional[int]

Number of alternative routes to return aside from the optimal route.

None
avoid Optional[Dict[str, List[str]]]

Avoid routes that violate certain features of road network or that go through user-specified geographical bounding boxes. Sample use of parameter: {"features": [controlledAccessHighway, tunnel]}

None
exclude Optional[Dict[str, List[str]]]

Defines properties which will be strictly excluded from route calculation. Sample use of parameter: {"countries": [A comma separated list of three-letter country codes (ISO-3166-1 alpha-3 code)]}

None
units Optional[herepy.here_enum.RoutingMetric]

Units of measurement used in guidance instructions. The default is metric.

None
lang Optional[str]

Default: "en-US" Specifies the preferred language of the response. The value should comply with the IETF BCP 47.

None
return_fields List[herepy.here_enum.RoutingApiReturnField]

Defines which attributes are included in the response as part of data representation of a Route or Section.

[<RoutingApiReturnField.polyline: 'polyline'>]
span_fields Optional[List[herepy.here_enum.RoutingApiSpanField]]

Defines which attributes are included in the response spans. For example, attributes,length will enable the fields attributes and length in the route response. This parameter also requires that the polyline option is set within the return parameter.

None
truck Optional[Dict[str, List[str]]]

Comma-separated list of shipped hazardous goods in the vehicle. Sample use of parameter: {"shippedHazardousGoods": [explosive, gas, flammable]}

None
scooter Optional[Dict[str, str]]

Scooter specific parameters. Sample use of parameter: {"allowHighway": "true"}

None
headers Optional[dict]

HTTP headers for requests. Sample: X-Request-ID User-provided token that can be used to trace a request or a group of requests sent to the service.

None

Returns:

Type Description
Optional[herepy.models.RoutingResponseV8]

RoutingResponseV8

Source code in herepy/routing_api.py
def route_v8(
    self,
    transport_mode: RoutingTransportMode,
    origin: Union[List[float], str],
    destination: Union[List[float], str],
    via: Optional[List[List[float]]] = None,
    departure_time: Optional[str] = None,
    routing_mode: RoutingMode = RoutingMode.fast,
    alternatives: Optional[int] = None,
    avoid: Optional[Dict[str, List[str]]] = None,
    exclude: Optional[Dict[str, List[str]]] = None,
    units: Optional[RoutingMetric] = None,
    lang: Optional[str] = None,
    return_fields: List[RoutingApiReturnField] = [RoutingApiReturnField.polyline],
    span_fields: Optional[List[RoutingApiSpanField]] = None,
    truck: Optional[Dict[str, List[str]]] = None,
    scooter: Optional[Dict[str, str]] = None,
    headers: Optional[dict] = None,
) -> Optional[RoutingResponseV8]:
    """Calculates the route between given origin and destination.
    Args:
      transport_mode (RoutingTransportMode):
        Mode of transport to be used for the calculation of the route.
      origin (Union[List[float], str]):
        List contains latitude and longitude in order
        or string with the location name.
      destination (Union[List[float], str]):
        List contains latitude and longitude in order
        or string with the location name.
      via (Optional[List[List[float]]]):
        Locations defining via waypoints.
        Locations between origin and destination.
      departure_time (Optional[str]):
        Specifies the time of departure as defined by
        either date-time or full-date T partial-time in RFC 3339,
        section 5.6 (for example, 2019-06-24T01:23:45).
      routing_mode (RoutingMode):
        Specifies which optimization is applied during route calculation,
        fast as default value.
      alternatives (Optional[int]):
        Number of alternative routes to return aside from the optimal route.
      avoid (Optional[Dict[str, List[str]]]):
        Avoid routes that violate certain features of road network or
        that go through user-specified geographical bounding boxes.
        Sample use of parameter: `{"features": [controlledAccessHighway, tunnel]}`
      exclude (Optional[Dict[str, List[str]]]):
        Defines properties which will be strictly excluded from route calculation.
        Sample use of parameter:
        `{"countries": [A comma separated list of three-letter country codes (ISO-3166-1 alpha-3 code)]}`
      units (Optional[RoutingMetric]):
        Units of measurement used in guidance instructions. The default is metric.
      lang (Optional[str]):
        Default: "en-US"
        Specifies the preferred language of the response.
        The value should comply with the IETF BCP 47.
      return_fields (List[RoutingApiReturnField]):
        Defines which attributes are included in the response as part of data
        representation of a Route or Section.
      span_fields (Optional[List[RoutingApiSpanField]]):
        Defines which attributes are included in the response spans.
        For example, attributes,length will enable the fields attributes and length in the route response.
        This parameter also requires that the polyline option is set within the return parameter.
      truck (Optional[Dict[str, List[str]]]):
        Comma-separated list of shipped hazardous goods in the vehicle.
        Sample use of parameter: `{"shippedHazardousGoods": [explosive, gas, flammable]}`
      scooter (Optional[Dict[str, str]]):
        Scooter specific parameters.
        Sample use of parameter: `{"allowHighway": "true"}`
      headers (Optional[dict]):
        HTTP headers for requests.
        Sample:
        X-Request-ID
        User-provided token that can be used to trace a request or
        a group of requests sent to the service.
    Returns:
      RoutingResponseV8
    Raises:
      HEREError
    """

    if isinstance(origin, str):
        origin = self._get_coordinates_for_location_name(origin)
    if isinstance(destination, str):
        destination = self._get_coordinates_for_location_name(destination)
    data = {
        "transportMode": transport_mode.__str__(),
        "origin": str.format("{0},{1}", origin[0], origin[1]),
        "destination": str.format("{0},{1}", destination[0], destination[1]),
        "apiKey": self._api_key,
    }
    if via:
        via_keys = []
        for i, v in enumerate(via):
            key = str.format("{0}{1}", "via", i)
            via_keys.append(key)
            data[key] = str.format("{0},{1}", v[0], v[1])
    if departure_time:
        data["departureTime"] = departure_time
    data["routingMode"] = routing_mode.__str__()
    if alternatives:
        data["alternatives"] = alternatives
    if avoid:
        key = list(avoid.keys())[0]
        values = list(avoid.values())[0]
        data["avoid"] = {
            key: ",".join(values),
        }
    if exclude:
        key = list(avoid.keys())[0]
        values = list(avoid.values())[0]
        data["exclude"] = {
            key: ",".join(values),
        }
    if units:
        data["units"] = units.__str__()
    if lang:
        data["lang"] = lang
    if return_fields:
        data["return"] = ",".join([field.__str__() for field in return_fields])
    if span_fields:
        data["spans"] = ",".join([field.__str__() for field in span_fields])
    if truck:
        key = list(avoid.keys())[0]
        values = list(avoid.values())[0]
        data["truck"] = {
            key: ",".join(values),
        }
    if scooter:
        data["scooter"] = scooter

    response = self.__get(
        self.URL_CALCULATE_ROUTE_V8,
        data,
        "routes",
        RoutingResponseV8,
        manipulation_key="via",
        keys_for_manipulation=via_keys,
    )
    return response

sync_matrix(self, origins, destinations, matrix_type=<MatrixRoutingType.world: 'world'>, center=None, radius=None, profile=None, departure=None, routing_mode=None, transport_mode=None, avoid=None, truck=None, matrix_attributes=None)

Sync request a matrix of route summaries between M starts and N destinations.

Parameters:

Name Type Description Default
origins Union[List[float], str]

List of lists of coordinates [lat,long] of start waypoints. or list of string with the location names.

required
destinations Union[List[float], str]

List of lists of coordinates [lat,long] of destination waypoints. or list of string with the location names.

required
matrix_type MatrixRoutingType

Routing type used in definition of a region in which the matrix will be calculated.

<MatrixRoutingType.world: 'world'>
center Optional[List[float]]

Center of region definition, latitude and longitude.

None
radius Optional[int]

Center of region definition.

None
profile Optional[herepy.here_enum.MatrixRoutingProfile]

A profile ID enables the calculation of matrices with routes of arbitrary length.

None
departure str

time when travel is expected to start, e.g.: '2013-07-04T17:00:00+02'

None
routing_mode Optional[herepy.here_enum.MatrixRoutingMode]

Route mode used in optimization of route calculation.

None
transport_mode Optional[herepy.here_enum.MatrixRoutingTransportMode]

Depending on the transport mode special constraints, speed attributes and weights are taken into account during route calculation.

None
avoid Optional[herepy.objects.Avoid]

Avoid routes that violate these properties.

None
truck Optional[herepy.objects.Truck]

Different truck options to use during route calculation when transportMode = truck.

None
matrix_attributes Optional[List[herepy.here_enum.MatrixSummaryAttribute]]

List of MatrixSummaryAttribute enums.

None

Returns:

Type Description
Optional[herepy.models.RoutingMatrixResponse]

RoutingMatrixResponse

Exceptions:

Type Description
HEREError

If an error is received from the server.

Source code in herepy/routing_api.py
def sync_matrix(
    self,
    origins: Union[List[float], str],
    destinations: Union[List[float], str],
    matrix_type: MatrixRoutingType = MatrixRoutingType.world,
    center: Optional[List[float]] = None,
    radius: Optional[int] = None,
    profile: Optional[MatrixRoutingProfile] = None,
    departure: str = None,
    routing_mode: Optional[MatrixRoutingMode] = None,
    transport_mode: Optional[MatrixRoutingTransportMode] = None,
    avoid: Optional[Avoid] = None,
    truck: Optional[Truck] = None,
    matrix_attributes: Optional[List[MatrixSummaryAttribute]] = None,
) -> Optional[RoutingMatrixResponse]:
    """Sync request a matrix of route summaries between M starts and N destinations.
    Args:
      origins (List):
        List of lists of coordinates [lat,long] of start waypoints.
        or list of string with the location names.
      destinations (List):
        List of lists of coordinates [lat,long] of destination waypoints.
        or list of string with the location names.
      matrix_type (MatrixRoutingType):
        Routing type used in definition of a region in which the matrix will be calculated.
      center (Optional[List]):
        Center of region definition, latitude and longitude.
      radius (Optional[int]):
        Center  of region definition.
      profile (Optional[MatrixRoutingProfile]):
        A profile ID enables the calculation of matrices with routes of arbitrary length.
      departure (str):
        time when travel is expected to start, e.g.: '2013-07-04T17:00:00+02'
      routing_mode (Optional[MatrixRoutingMode]):
        Route mode used in optimization of route calculation.
      transport_mode (Optional[MatrixRoutingTransportMode]):
        Depending on the transport mode special constraints, speed attributes and weights
        are taken into account during route calculation.
      avoid (Optional[Avoid]):
        Avoid routes that violate these properties.
      truck (Optional[Truck]):
        Different truck options to use during route calculation when transportMode = truck.
      matrix_attributes (List):
        List of MatrixSummaryAttribute enums.
    Returns:
      RoutingMatrixResponse
    Raises:
      HEREError: If an error is received from the server.
    """

    query_params = {
        "apiKey": self._api_key,
        "async": "false",
    }

    request_body = self.__prepare_matrix_request_body(
        origins=origins,
        destinations=destinations,
        matrix_type=matrix_type,
        center=center,
        radius=radius,
        profile=profile,
        departure=departure,
        routing_mode=routing_mode,
        transport_mode=transport_mode,
        avoid=avoid,
        truck=truck,
        matrix_attributes=matrix_attributes,
    )

    url = Utils.build_url(self.URL_CALCULATE_MATRIX, extra_params=query_params)
    headers = {"Content-Type": "application/json"}
    response = requests.post(
        url, json=request_body, headers=headers, timeout=self._timeout
    )
    json_data = json.loads(response.content.decode("utf8"))
    if json_data.get("matrix") is not None:
        return RoutingMatrixResponse.new_from_jsondict(json_data)
    else:
        raise HEREError("Error occured on " + sys._getframe(1).f_code.co_name)

truck_route(self, waypoint_a, waypoint_b, modes=None, departure='now')

Calculates the fastest truck route between two location

Parameters:

Name Type Description Default
waypoint_a Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
waypoint_b Union[List[float], str]

List contains latitude and longitude in order or string with the location name.

required
modes List[herepy.here_enum.RouteMode]

List contains RouteMode enums.

None
departure str

Date time str in format yyyy-mm-ddThh:mm:ss. Default now.

'now'

Returns:

Type Description
Optional[herepy.models.RoutingResponse]

RoutingResponse

Source code in herepy/routing_api.py
def truck_route(
    self,
    waypoint_a: Union[List[float], str],
    waypoint_b: Union[List[float], str],
    modes: List[RouteMode] = None,
    departure: str = "now",
) -> Optional[RoutingResponse]:
    """Calculates the fastest truck route between two location
    Args:
      waypoint_a (List):
        List contains latitude and longitude in order
        or string with the location name.
      waypoint_b (List):
        List contains latitude and longitude in order
        or string with the location name.
      modes (List):
        List contains RouteMode enums.
      departure (str):
        Date time str in format `yyyy-mm-ddThh:mm:ss`. Default `now`.
    Returns:
      RoutingResponse
    Raises:
      HEREError"""

    if modes is None:
        modes = [RouteMode.truck, RouteMode.fastest]
    return self._route(waypoint_a, waypoint_b, modes, departure)

WaypointNotFoundError

Waypoint not found Error Type.

This error indicates that one of the requested waypoints (start/end or via point) could not be found in the routing network.

error_from_routing_service_error(json_data)

Return the correct subclass for routing errors

Source code in herepy/routing_api.py
def error_from_routing_service_error(json_data):
    """Return the correct subclass for routing errors"""

    if "error" in json_data:
        if json_data["error"] == "Unauthorized":
            return InvalidCredentialsError(json_data["error_description"])

    if "subtype" in json_data:
        subtype = json_data["subtype"]
        details = json_data["details"]

        if subtype == "InvalidInputData":
            return InvalidInputDataError(details)
        if subtype == "WaypointNotFound":
            return WaypointNotFoundError(details)
        if subtype == "NoRouteFound":
            return NoRouteFoundError(details)
        if subtype == "LinkIdNotFound":
            return LinkIdNotFoundError(details)
        if subtype == "RouteNotReconstructed":
            return RouteNotReconstructedError(details)
    # pylint: disable=W0212
    return HEREError("Error occured on " + sys._getframe(1).f_code.co_name)