Hands On

The Secret Lives of APIs — Part Deux: Map Image & Public Transport Logos

By Richard Süselbeck | 15 January 2020

One of the things I like to do is highlight neat API features you may not yet know about. For example, did you know that the Map Image API supports Routing? (Click here to find out how!)

In this blog post, I'm once again going to look at the Map Image API. This API lives in the shadows of its bigger brothers, the interactive maps found in our Mobile and Web SDKs. However, it's both a powerful and lightweight API, which can be really useful in contexts where interactive maps don't make sense or simply cannot be used. Think of putting maps into emails or displaying locations on an Echo Show!

Like many of our APIs, the Map Image API also hides a few neat features you may not be aware of, so I've decided to write a series of short blog posts to bring these hidden features to light. Today we're going to look at how to generate the logos of public transit companies using the Map Image API. Let’s have a look at a quick example.


https://image.maps.api.here.com/mia/1.6/companylogo
  ?app_id=your_app_id
  &app_code=your_app_code
  &logoid=1611547c89c9be1164df5a04d8f393f9
  &;w=250
  &;h=250
  &f=0  
sbahnlogo

As we can see, when using the “companylogo” resource, the API returns an image of a logo instead of a map. In this case, you may recognize the logo as that of the S-Bahn in Germany. Let’s look at the various parameters we’ve used.

  • app_id/app_code: These are your credentials. If you don’t have a set of credentials yet, go ahead an sign up for our Freemium account here on the portal.
  • logoid: This is the unique id for the logo you want to generate an image of.
  • h/w: As you would probably guess, these are the dimensions (height/weight) of the image in pixels.
  • f: This represents the image format. In this case, we’ve chosen PNG, though other formats like JPG (1) or SVG (5) are also available.

You can take at look at the documentation to see a complete list of parameters and values.

Now you’re probably wondering, where the heck we are getting the logoid from. The answer is that we’re getting it from the Routing API!

When request a public transport route using the Routing API, it can provide you with the logoid for the transit lines used in the route. However, it will not do so by default. Because the Routing API is so powerful, it will not return all available information in every response, as the response would become unwieldy. To request this additional information, you can use various attribute parameters. In our case, we want to use the “lineattributes” parameter and the “companyLogo” value. Let’s look at an example.


https://route.api.here.com/routing/7.2/calculateroute.json
  ?app_id=your_app_code
  &app_code=your_app_id
  &mode=fastest;publicTransport
  &waypoint0=52.5208,13.4093
  &waypoint1=52.5034,13.3295
  &combineChange=true
  &lineattributes=companyLogo  

As you can see, this is a standard routing request, except that we are also asking for the company logo id to be included in the line information. Here’s the snippet from the response, which contains the id we are looking for under "filename".


"publicTransportLine": [
    … ,
    {
        "lineName": "S9",
        "lineForeground": "#80004D",
        "lineBackground": "#80004D",
        "companyName": "",
        "companyShortName": "",
        "companyLogo": {
            "resourceType": "vendorIcon",
            "filename": "1611547c89c9be1164df5a04d8f393f9"
        },
        "destination": "S+U Friedrichstr. Bhf",
        "type": "railRegional",
        "id": "L2"
    },
	…
]

Note that not every public transport line necessarily has a logo in the database. That said, why not try it in New York to get the logo of the MTA (59f265c196ffe8335dcf887b4f8ed48d) or Paris to get the logo of the Métro (5f4a858eb573203acc40eb5585017fae).

mtametrologos-1

Until next time, when we will reveal even more API secrets!