Adding the transit layer

Public transit lines have immense importance in cities, especially for tourists and foreigners in the city. Mapping these transit lines (bus, underground, and so on) onto the base maps of several cities is a tedious task, and this is what the Google Maps JavaScript API offers through its special objects.

In this recipe, we will add transit layers to the Google Maps map interface.

Getting ready

Continuing from the previous recipe, Adding the traffic layer, will simplify our work, as we will only replace the TrafficLayer object with TransitLayer classes. Remember to copy the code of the original recipe.

How to do it…

Here are the steps to show public transit lines as an overlay:

  1. Delete TrafficLayer related lines (the last two ...

Get Google Maps JavaScript API Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.