Page Summary
-
The Maps JavaScript API offers Traffic, Transit, and Bicycling layers to enhance the base map with real-time information.
-
These layers provide data on current traffic conditions, public transit networks, and bicycle routes, respectively.
-
The layers are implemented using
TrafficLayer,TransitLayer, andBicyclingLayerobjects and are available in select regions. -
Transit Layer data is sourced from the Google Transit Partner Program, and public agencies can contribute their city's data.
-
Bicycling Layer visually differentiates dedicated bike routes, bike lanes, and recommended paths using varying colors and styles.
The Traffic, Transit, and Bicycling layers modify the base map layer to display current traffic conditions, local transit networks, or bicycling route information. These layers are available in select regions.
Traffic Layer
The Maps JavaScript API allows you to add real-time traffic
information (where supported) to your maps using the TrafficLayer
object. Traffic information is refreshed frequently, but not instantly. Rapid
consecutive requests for the same area are unlikely to yield different
results.
TypeScript
async function init(): Promise<void> { const { TrafficLayer } = await google.maps.importLibrary('maps'); const mapElement = document.querySelector<google.maps