Accessing Location Services

Overview

The HERE Data SDK for Python provides generic access to all HERE platform Location Services given their HRN. This includes the ability to perform REST requests, such as GET, HEAD, POST, PUT, PATCH and DELETE calls to the API endpoints with no need for you to deal with authentication, authorization and base API lookup manually.

For details on all the available methods please see the API reference of the Service class.

Discover and Access Services

Services can be discovered in the HERE platform Portal but also programmatically by listing all the services your account has access to.

Get a list of all services

from here.platform import Platform
platform = Platform()

services = platform.list_services()

for service in services:
    print(f"{service.name} ({service.hrn})")

resulting in:

Fuel prices (hrn:here:service::olp-here:fuel-prices-3)
HERE Destination Weather (hrn:here:service::olp-here:destination-weather-3)
HERE Isoline Routing (hrn:here:service::olp-here:routing-isoline-8)
HERE Routing (hrn:here:service::olp-here:routing-8)
HERE Routing - Transit (hrn:here:service::olp-here:transit-routing-8)
HERE Search - One Box Search (hrn:here:service::olp-here:search-discover-7)
HERE Search - Reverse Geocoder (hrn:here:service::olp-here:search-revgeocode-7)

(list truncated for clarity)

Get a single service

You can connect to a service by providing its HRN.

routing_service = platform.get_service("hrn:here:service::olp-here:routing-8")

Each service can also be opened and inspected directly on the platform portal.

routing_service.open_in_portal()

Obtain basic properties of a service

Key properties of the service are exposed as attributes. Additional properties are presents in the service configuration.

print('',
   'HRN:           ', routing_service.hrn, '\n',
   'Version:       ', routing_service.version, '\n',
   'Name:          ', routing_service.name, '\n',
   'Base URL:      ', routing_service.base_url, '\n',
   'Summary:       ', routing_service.summary, '\n',
   'Tags:          ', routing_service.tags, '\n',
)

A possible output:

 HRN:            hrn:here:service::olp-here:routing-8 
 Version:        8.29.1 
 Name:           HERE Routing 
 Base URL:       https://router.hereapi.com/v8 
 Summary:        The Routing service end point calculates routes between two or more locations using various transport modes and provides additional route-related information. The Routing API is customizable so that the route calculation and additional information can be adapted to both consumer and enterprise applications. 
 Tags:           ['Waypoints', 'Navigation', 'Directions', 'Traffic', 'Pedestrian', 'Routing', 'Vehicle', 'HERE', 'ETA', 'Short route', 'Route shape', 'Car', 'Fast route', 'Alternative routes', 'Route']

Examples of Services and REST API Calls

You can invoke services directly, without the need to authenticate and prepend the service base URL manually in each API call. GET, HEAD, POST, PUT, PATCH and DELETE calls can be performed on the service object via the corresponding Python methods.

For the detailed guide and technical specification of REST APIs exposed, please consult the documentation of each service, accessible via the platform Portal and the HERE Developer Portal.

Isoline routing

An example of isoline route request that shows the area reachable by car from place located on a main road in central Germany in 1 km and 10 km.

The following performs a GET request, the parameters are passed in the query string.

from here.platform import Platform

platform = Platform()
isoline = platform.get_service("hrn:here:service::olp-here:routing-isoline-8")

params = {
    "origin": "51.611571,11.351608",
    "range[type]": "distance",
    "range[values]": "1000,10000",
    "transportMode": "car"
}

result = isoline.get("/isolines", params=params)

The result is a dictionary with the following content:

{
    "departure": {
        "time": "2021-10-21T15:54:17+00:00",
        "place": {
            "type": "place",
            "location": {
                "lat": 51.6114166,
                "lng": 11.3517286
            },
            "originalLocation": {
                "lat": 51.611571,
                "lng": 11.3516079
            }
        }
    },
    "isolines": [
        {
            "range": {
                "type": "distance",
                "value": 1000
            },
            "polygons": [
                {
                    "outer": "BGy4guiDkrl0V-qBmgBuVqgCAwhIuVsgC-qB-qBu"
                }
            ]
        },
        {
            "range": {
                "type": "distance",
                "value": 10000
            },
            "polygons": [
                {
                    "outer": "BGurztiDs7jsV8qBmgBuVsgCAq3KtVsgC7qB8qBv"
                }
            ]
        }
    ]
}

(polygon contours truncated for clarity)

In this specific example, polygons representing isolines are encoded using flexpolyline. Encoded strings can be decoded using the flexpolyline Python package. Usage of this encoding is common among the routing services and their APIs.

Next transit departures

An example of a query to the transit service that exposes the next transit departures in the area of the NESCO IT Park in Mumbai, India.

The following performs a GET request, the parameters are passed in the query string.

from here.platform import Platform

platform = Platform()
next_departures = platform.get_service("hrn:here:service::olp-here:transit-next-departures-8")

params = {
    "in": "19.152351636582207,72.85587912861622,r=50",
    "maxPlaces": 10
}

result = next_departures.get("/departures", params=params)

The result is a dictionary with the following content:

{
    "boards": [
        {
            "place": {
                "name": "Mahananda Dairy",
                "type": "station",
                "location": {
                    "lat": 19.150885,
                    "lng": 72.85633
                },
                "id": "408202729"
            },
            "departures": [
                {
                    "time": "2021-10-21T20:59:00+05:30",
                    "transport": {
                        "mode": "bus",
                        "name": "40LTD",
                        "category": "Bus",
                        "headsign": "Borivali Station East",
                        "shortName": "40LTD",
                        "longName": "40LTD"
                    },
                    "agency": {
                        "id": "bhB00000",
                        "name": "BEST (The Brihanmumbai Electric Supply & Transport)",
                        "website": "https://www.bestundertaking.com/in/"
                    }
                }
            ]
        },
        {
            "place": {
                "name": "Vanrai Colony",
                "type": "station",
                "location": {
                    "lat": 19.153904,
                    "lng": 72.856668
                },
                "id": "408209293"
            },
            "departures": [
                {
                    "time": "2021-10-21T20:58:00+05:30",
                    "transport": {
                        "mode": "bus",
                        "name": "C72EXP",
                        "category": "Bus",
                        "headsign": "Bhayander Station East",
                        "shortName": "C72EXP",
                        "longName": "C72EXP"
                    },
                    "agency": {
                        "id": "bhB00000",
                        "name": "BEST (The Brihanmumbai Electric Supply & Transport)",
                        "website": "https://www.bestundertaking.com/in/"
                    }
                }
            ]
        }
    ]
}

(result truncated for clarity)

Network positioning

An example of a positioning query to determine the location a mobile device through the signals it receives from the LTE network. The service discovers that the position of the device is in Berlin, Germany.

The following performs a POST request, the parameters are included in the body of the request.

from here.platform import Platform

platform = Platform()
positioning = platform.get_service("hrn:here:service::olp-here:positioning-2")

data = {
    "lte": [
        {
            "mcc": 262,
            "mnc": 2,
            "cid": 2898945,
            "rsrp": -50, "rsrq": -5,
            "nmr": [
                { "earfcn": 6300, "pci": 237, "rsrp": -60, "rsrq": -6 },
                { "earfcn": 6300, "pci": 442, "rsrp": -70, "rsrq": -7 }
            ]
        }
    ]
}

result = positioning.post("/locate", data=data)

The result is a dictionary with the following content:

{
    "location": {
        "lat": 52.51812458,
        "lng": 13.37465286,
        "accuracy": 2139
    }
}

results matching ""

    No results matching ""