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.

Marker Collision Management

  • Advanced Markers on vector maps allow you to control how markers behave when they overlap, usingAdvancedMarkerView.collisionBehavior.

  • Three collision behaviors are available:REQUIRED (always display),OPTIONAL_AND_HIDES_LOWER_PRIORITY (hide if overlapping), andREQUIRED_AND_HIDES_OPTIONAL (always display and hide overlapping optional markers or labels).

  • Collision detection with basemap labels is only supported on vector maps, while raster maps only detect marker-to-marker collisions.

  • This page provides code samples in TypeScript and JavaScript demonstrating how to implement and manage marker collision behaviors.

Handle marker collisions

Collision behavior controls how a marker will display if it collides (overlaps)with another marker. Collision behavior is only supported when usingAdvanced Markers on a vectormap.

To set collision behavior, setAdvancedMarkerView.collisionBehavior to one ofthe following:

  • REQUIRED: (default) Always display the marker regardless of collision.
  • OPTIONAL_AND_HIDES_LOWER_PRIORITY Display the marker only if it does notoverlap with other markers. If two markers of this type would overlap, the onewith the higherzIndex is shown. If they have the samezIndex, the one withthe lower vertical screen position is shown.
  • REQUIRED_AND_HIDES_OPTIONAL Always display the marker regardless ofcollision, and hide anyOPTIONAL_AND_HIDES_LOWER_PRIORITY markers or labelsthat would overlap with the marker.
Note: On raster maps, only marker-to-marker collisions are detected. Markercollisions with basemap labels are supported only on vector maps.

The following example always displays markers and hides underlying labels:

constadvancedMarker=newgoogle.maps.marker.AdvancedMarkerView({position:newgoogle.maps.LatLng({lat,lng}),map,collisionBehavior:google.maps.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL,});

The following example hides markers if they collide with a required marker andhides underlying labels:

constadvancedMarker=newgoogle.maps.marker.AdvancedMarkerView({position:newgoogle.maps.LatLng({lat,lng}),map,collisionBehavior:google.maps.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY,});

TypeScript

constmapElement=document.querySelector("gmp-map")asgoogle.maps.MapElement;// Initialize and add the mapasyncfunctioninitMap():Promise<void>{// Request needed libraries.const{Map}=(awaitgoogle.maps.importLibrary("maps"))asgoogle.maps.MapsLibrary;const{AdvancedMarkerElement}=(awaitgoogle.maps.importLibrary("marker"))asgoogle.maps.MarkerLibrary;letmarkers:google.maps.marker.AdvancedMarkerElement[]=[];letcollisionBehavior=google.maps.CollisionBehavior.REQUIRED;// @ts-ignoreconstselect=newmdc.select.MDCSelect(document.querySelector(".mdc-select")asHTMLElement);select.listen("MDCSelect:change",()=>{collisionBehavior=select.value;markers.forEach((marker)=>{marker.collisionBehavior=collisionBehavior;});});select.value=collisionBehavior;// Create some markers on the mapletlocations=[[-122.3402,47.6093],[-122.3402,47.6094],[-122.3403,47.6094],[-122.3384,47.6098],[-122.3389,47.6095],[-122.3396,47.6095],[-122.3379,47.6097],[-122.3378,47.6097],[-122.3396,47.6091],[-122.3383,47.6089],[-122.3379,47.6093],[-122.3381,47.6095],[-122.3378,47.6095],];locations.forEach(([lng,lat]:number[])=>{constadvancedMarker=newAdvancedMarkerElement({position:newgoogle.maps.LatLng({lat,lng}),collisionBehavior:collisionBehavior,});mapElement.appendChild(advancedMarker);markers.push(advancedMarker);});}initMap();
Note: Read theguide on using TypeScript and Google Maps.

JavaScript

constmapElement=document.querySelector("gmp-map");// Initialize and add the mapasyncfunctioninitMap(){// Request needed libraries.const{Map}=(awaitgoogle.maps.importLibrary("maps"));const{AdvancedMarkerElement}=(awaitgoogle.maps.importLibrary("marker"));letmarkers=[];letcollisionBehavior=google.maps.CollisionBehavior.REQUIRED;// @ts-ignoreconstselect=newmdc.select.MDCSelect(document.querySelector(".mdc-select"));select.listen("MDCSelect:change",()=>{collisionBehavior=select.value;markers.forEach((marker)=>{marker.collisionBehavior=collisionBehavior;});});select.value=collisionBehavior;// Create some markers on the mapletlocations=[[-122.3402,47.6093],[-122.3402,47.6094],[-122.3403,47.6094],[-122.3384,47.6098],[-122.3389,47.6095],[-122.3396,47.6095],[-122.3379,47.6097],[-122.3378,47.6097],[-122.3396,47.6091],[-122.3383,47.6089],[-122.3379,47.6093],[-122.3381,47.6095],[-122.3378,47.6095],];locations.forEach(([lng,lat])=>{constadvancedMarker=newAdvancedMarkerElement({position:newgoogle.maps.LatLng({lat,lng}),collisionBehavior:collisionBehavior,});mapElement.appendChild(advancedMarker);markers.push(advancedMarker);});}initMap();
Note: The JavaScript is compiled from the TypeScript snippet.

CSS

:root{--mdc-theme-primary:#1a73e8;--mdc-theme-secondary:#rgb(225,245,254);--mdc-theme-on-primary:#fff;--mdc-theme-on-secondary:rgb(1,87,155);}.mdc-text-field--focused:not(.mdc-text-field--disabled).mdc-floating-label{color:var(--mdc-theme-primary);}.mdc-select--focused.mdc-select__dropdown-icon{background:url(data:image/svg+xml,%3Csvg%20width%3D%2210px%22%20height%3D%225px%22%20viewBox%3D%227%2010%2010%205%22%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%3E%0A%20%20%20%20%3Cpolygon%20id%3D%22Shape%22%20stroke%3D%22none%22%20fill%3D%22%23000%22%20fill-rule%3D%22evenodd%22%20opacity%3D%220.54%22%20points%3D%227%2010%2012%2015%2017%2010%22%3E%3C%2Fpolygon%3E%0A%3C%2Fsvg%3E)no-repeatcenter;}.mdc-select:not(.mdc-select--disabled).mdc-select--focused.mdc-floating-label{color:var(--mdc-theme-primary);}/* Optional: Makes the sample page fill the window. */html,body{height:100%;margin:0;padding:0;}#container{height:100%;display:flex;}#sidebar{flex-basis:15rem;flex-grow:1;padding:1rem;max-width:33rem;height:100%;box-sizing:border-box;overflow:auto;}gmp-map{flex-basis:0;flex-grow:4;height:100%;}.mdc-select,.mdc-select__anchor,.mdc-select__menu{width:100%;}

HTML

<html>    <head>        <title>Advanced Marker Collision Management</title>        <link            href="https://unpkg.com/material-components-web@6.0.0/dist/material-components-web.css"            rel="stylesheet" />        <script src="https://unpkg.com/material-components-web@6.0.0/dist/material-components-web.min.js"></script>        <link            rel="stylesheet"            href="https://fonts.googleapis.com/icon?family=Material+Icons" />        <link rel="stylesheet" type="text/css" href="./style.css" />        <script type="module" src="./index.js"></script>        <!-- prettier-ignore -->        <script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})        ({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>    </head>    <body>        <div>            <gmp-map                center="47.609414458375674,-122.33897030353548"                zoom="17"                map-id="6ff586e93e18149f"></gmp-map>            <div>                <div>                    <div                                               aria-labelledby="outlined-select-label">                        <input                            type="text"                            disabled                            readonly                                                       />                        <i></i>                        <span>                            <span></span>                            <span>                                <span                                                                                                          >Pick a Collision Behavior</span                                >                            </span>                            <span></span>                        </span>                    </div>                    <div>                        <ul>                            <li data-value="REQUIRED">                                Required                            </li>                            <li                                                               data-value="REQUIRED_AND_HIDES_OPTIONAL">                                Required and hides optional                            </li>                            <li                                                               data-value="OPTIONAL_AND_HIDES_LOWER_PRIORITY">                                Optional and hides lower priority                            </li>                        </ul>                    </div>                </div>            </div>        </div>    </body></html>

Try Sample

Clone Sample

Git and Node.js are required to run this sample locally. Follow theseinstructionsto install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

gitclonehttps://github.com/googlemaps-samples/js-api-samples.gitcdsamples/advanced-markers-collisionnpminpmstart

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.