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.
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.
Here are the steps to show public transit lines as an overlay:
Delete
TrafficLayer
related lines (the last two lines).Instead of the
TrafficLayer
object, use theTransitLayer
object:var transitLayer = new google.maps.TransitLayer();
Add the
TransitLayer
object to the map:transitLayer.setMap(map);
You can see the public transit lines as an overlay on Google...