Places UI Kit: A ready-to-use library that provides room for customization and low-code development. Try it out, and share yourinput on your UI Kit experience.

Layers

  • Layers in Maps JavaScript API are objects consisting of multiple items that are treated as a single unit and often represent collections of objects on the map.

  • The API provides various layer types, including Data, Heatmap, KML, Traffic, Transit, and Bicycling layers, each serving a distinct purpose for displaying geospatial data.

  • You can easily add or hide a layer by calling thesetMap() method, providing the map object ornull respectively.

  • The example code demonstrates adding a Transit layer to a map centered on London.

Select platform:AndroidJavaScript

Layers are objects on the map that consist of one or more separate items,but are manipulated as a single unit. Layers generally reflect collections ofobjects that you add on top of the map to designate a common association. TheMaps JavaScript API manages the presentation of objects within layersby rendering their constituent items into one object (typically a tile overlay) anddisplaying them as the map's viewport changes. Layers may also alter the presentationlayer of the map itself, slightly altering the base tiles in a fashionconsistent with the layer. Note that most layers, by design, may not beaccessed using their individual objects, but may only be manipulated as aunit.

Layers Overview

The Maps JavaScript API has several types of layers:

  • TheGoogle Maps Data layer provides a container for arbitrary geospatial data. You can use the Data layer to store your custom data, or to display GeoJSON data on a Google map.
  • TheKML layer renders KML and GeoRSS elements into a Maps JavaScript API tile overlay.
  • TheTraffic layer displays traffic conditions on the map.
  • TheTransit layer displays the public transport network of your city on the map.
  • TheBicycling layer object renders a layer of bike paths and/or bicycle-specific overlays into a common layer. This layer is returned by default within theDirectionsRenderer when requesting directions of travel modeBICYCLING.

Add a layer

To add a layer to a map, you only need to callsetMap(),passing it the map object on which to display the layer. Similarly, to hide alayer, callsetMap(), passingnull.

The below snippet centers the map on London, UK, and adds theTransitlayer.

varmapOptions={zoom:13,center:newgoogle.maps.LatLng(51.5,-0.11)}varmap=newgoogle.maps.Map(document.getElementById("map"),mapOptions);vartransitLayer=newgoogle.maps.TransitLayer();transitLayer.setMap(map);

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-21 UTC.