Skip to main content
APIs 6 min read

Discovering Europe's Efficient Public Transit System with Public Transit Station Search API v8

Public Transit Station Search

During my recent trip to Europe, I had the opportunity to experience the remarkable public transit systems in countries like Spain, France, and the Netherlands. The efficiency and convenience of these networks left a lasting impression on me. Interestingly, the Netherlands is not only home to an impressive transportation infrastructure but also the headquarters of HERE Technologies, the world's #1 location platform. One of the remarkable location services, the Public Transit API v8, caught my attention. The Public Transit API v8 offers three REST APIs, namely Public Transit Routing API v8Public Transit Next Departures API v8, and Public Transit Station Search API v8. In this blog post, we will delve into the details of the Public Transit Station Search API v8 and its integration with the Maps API for Javascript.

Exploring the Public Transit Station Search API v8

The Public Transit Station Search API v8 offers a comprehensive solution for discovering transit stations within a specified area. By leveraging this API, developers gain access to essential information about transit stations, enabling them to provide valuable features and functionalities to users.

Key Features and Common Use Cases

  1. Retrieving Stations by Ids: If you possess the identifier of a particular station and wish to obtain its relevant information, the Public Transit Station Search API v8 allows you to fetch station details efficiently. By submitting a query with the desired station ID, the API responds with specific information related to the requested station.

  2. Searching Stations by Location: When you want to identify transit stations within a designated location, the API empowers you to search for stations falling within a circular area. By specifying the center of the search area using latitude and longitude coordinates and setting the radius, you can obtain a list of stations located within that range. This functionality proves particularly useful in exploring transit options near a specific point of interest.

  3. Searching Stations by Name and Location: In scenarios where numerous stations are present within a particular location, searching for a specific station can be challenging. The Public Transit Station Search API v8 solves this problem by allowing you to search for stations by name within a given area. By combining the station name or part of it with optional parameters like method and maxPlaces, you can refine your search and limit the number of stations in the API response.

Making API Requests

To interact with the Public Transit Station Search API v8, developers can utilize three different types of queries:

  • Search Stations by Ids: To retrieve information about a station with a known identifier, simply include the comma-separated list of station identifiers in the "ids" parameter of the API request.
Copied
        GET https://transit.hereapi.com/v8/stations
    ?ids=415712984
Authorization: Bearer 
  
  • Search Stations by Location: To discover transit stations within a specific location, provide the latitude and longitude coordinates as the "in" parameter, and optionally specify the radius of the search area using the "r" parameter.

Copied
        GET https://transit.hereapi.com/v8/stations
    ?in=41.90123,12.50091
Authorization: Bearer 
  
  • Search Stations by Name and Location: When searching for a station by name within a particular location, use the "in" parameter to define the center of the search area. Combine it with the "name" parameter, representing the station name or part of it, to narrow down the results. Additional parameters like "r" and "maxPlaces" can be employed to refine the search further.

Copied
        GET https://transit.hereapi.com/v8/stations
    ?in=41.90123,12.50091
    &name=termini
Authorization: Bearer 

  

API Response

The response to the request contains the following information blocks:

  • a maximum of 50 station identifiers are allowed in a single query. (25 station identifiers for Search by Name and Location)
  • each station element in the stations response object includes the following high-level elements:
    • place with station/stop information such as name, location, ID, type.
    • transports with information about the transports serving the station. Add return=transport in request to enable it.
    • accessPoints with information about points that are used to access the station/stop.
Copied
        {
  "stations": [
    {
      "place": {
        "name": "Roma Termini",
        "type": "station",
        "location": {
          "lat": 41.90054,
          "lng": 12.502168
        },
        "id": "415712984"
      },
      "accessPoints": [
        {
          "location": {
            "lat": 52.531679,
            "lng": 13.381779
          },
          "name": "North Entrance",
          "type": "accessPoint"
        },
        {
          "location": {
            "lat": 52.531678,
            "lng": 13.381778
          },
          "name": "West Entrance",
          "type": "accessPoint"
        },
        {
          "location": {
            "lat": 52.531672,
            "lng": 13.381773
          },
          "name": "Main Entrance",
          "type": "accessPoint"
        }
      ]
    }
  ]
}

  

Integration with the Maps API for Javascript

The class H.service.publicTransit.Service encapsulates the HERE Public Transit API in a service stub, providing methods to access its resources. And the method getStations(params,onResult,onError) sends a request to the Public Transit API to get transit stations within a given ids, name, and location. The supported parameters are the same as the REST requests above. 

Copied
        function pubicTransportGetStations(platform, at) {
  var publicTransit = platform.getPublicTransitService(),
      publicTransitParameters = {
        in:'41.90123,12.50091;r=1000',
        return:'transport',
        maxPlaces:50
      };

  publicTransit.getStations(
    publicTransitParameters,
    onSuccess,
    onError
  );
}
  

Sample Application

Below is the sample application showing several major transit in Europe as a request parameter to the Public Transit Station Search API, and it would show response from the API including the name of the station and one of the transports. This sample is built using HERE Maps API for Javascript and modified from the Search for a Location based on an Address sample. The source code for this sample application can be found in our HERE Github repo

Conclusion

Public Transit Station Search API v8 allows developers to unlock a wealth of transit station information and enhance user experiences within their applications. By leveraging the power of this API and integrating it with other tools like the Maps API for Javascript, businesses and individuals can access valuable data about stations, streamline their travel planning, and optimize their public transit journeys. Embracing innovative solutions like this API contributes to the creation of efficient and user-friendly transportation systems worldwide.

Resources

 

Erwin Soekianto

Erwin Soekianto

Developer Evangelist

Have your say

Sign up for our newsletter

Why sign up:

  • Latest offers and discounts
  • Tailored content delivered weekly
  • Exclusive events
  • One click to unsubscribe