Class: Service
- Last UpdatedMay 21, 2025
- 4 minute read
H.service.publicTransit.Service
This class encapsulates the HERE Public Transit API in a service stub, providing methods to access its resources.
It's not allowed to call the constructor directly (an IllegalOperationError
is thrown).
Instead an instance of this Service can be retrieved by calling the factory method
H.service.Platform#getPublicTransitService
on a platform instance.
Name | Type | Description |
---|---|---|
options |
H.service.Options |
Configuration options for Public Transit service. |
Throws:
-
If instantiated directly.
Example
// Assumption: the platform is instantiated
let publicTransitService = platform.getPublicTransitService();
publicTransitService.getRoutes({
origin: '41.79457,12.25473',
destination: '41.90096,12.50243',
return: 'polyline'
}, (result) => {
const sections = result.routes[0].sections;
const lineStrings = [];
sections.forEach((section) => {
// convert Flexible Polyline encoded string to geometry
lineStrings.push(H.geo.LineString.fromFlexiblePolyline(section.polyline));
});
const multiLineString = new H.geo.MultiLineString(lineStrings);
const bounds = multiLineString.getBoundingBox();
// render route on the map
map.addObject(new H.map.Polyline(multiLineString, {style: {lineWidth: 5}}));
// zoom to polyline
map.getViewModel().setLookAtData({bounds});
}, console.error);
Extends
Members
-
The property name to use when specifying options for this service within the
H.service.Platform.Options#servicesConfig
.
Methods
-
addEventListener (type, handler, opt_capture, opt_scope) inherited
-
This method adds a listener for a specific event.
Note that to prevent potential memory leaks, you must either call
removeEventListener
ordispose
on the given object when you no longer need it. -
addOnDisposeCallback (callback, opt_scope) inherited
-
This method adds a callback which is triggered when the
EventTarget
object is being disposed.Name Type Description callback
function The callback function.
opt_scope
Object optional An optional scope for the callback function
-
dispatchEvent (evt) inherited
-
This method dispatches an event on the
EventTarget
object.Name Type Description evt
H.util.Event | string An object representing the event or a string with the event name
-
dispose () inherited
-
This method removes listeners from the given object. Classes that extend
EventTarget
may need to override this method in order to remove references to DOM Elements and additional listeners. -
getDepartures (params, onResult, onError)H.util.ICancelable
-
This method sends a request to the Public Transit API to get subsequent departures from a given station and calls the
onResult
callback function once the service response becomes available (providing aH.service.ServiceResult
object) or theonError
callback if a communication error occurred.Please refer to the Public Transit Next Departures API documentation for information about the supported request parameters and the response details.
Returns:
Type Description H.util.ICancelable a handle that allows to cancel the request. -
getRoutes (params, onResult, onError)H.util.ICancelable
-
This method sends a request to the Public Transit API to calculate a transit route and calls the
onResult
callback function once the service response becomes available (providing aH.service.ServiceResult
object) or theonError
callback if a communication error occurred.Please refer to the Public Transit Routing API documentation for information about the supported request parameters and the response details.
Returns:
Type Description H.util.ICancelable a handle that allows to cancel the request. -
getStations (params, onResult, onError)H.util.ICancelable
-
This method sends a request to the Public Transit API to get transit stations within a given area and calls the
onResult
callback function once the service response becomes available (providing aH.service.ServiceResult
object) or theonError
callback if a communication error occurred.Please refer to the Public Transit Station Search API documentation for information about the supported request parameters and the response details.
Returns:
Type Description H.util.ICancelable a handle that allows to cancel the request. -
getUrl ()H.service.Url inherited
-
This method returns the configured service URL.
Returns:
Type Description H.service.Url -
removeEventListener (type, handler, opt_capture, opt_scope) inherited
-
This method removes a previously added listener from the
EventTarget
instance.