En esta página, te indicamos cómo controlar los siguientes aspectos de Marcadores avanzados:
Cómo configurar el comportamiento de colisión de un marcador
Cómo configurar la altitud de un marcador
Cómo controlar la visibilidad de un marcador según el nivel de zoom del mapa
Cómo configurar el comportamiento de colisión de un marcador
El comportamiento de colisión controla cómo se mostrará un marcador si se superpone con otro. Esta conducta solo se admite en los mapas de vectores.
Para configurar el comportamiento de colisión, establece AdvancedMarkerElement.collisionBehavior en una de las siguientes opciones:
REQUIRED: (opción predeterminada) Indica que el marcador debe mostrarse siempre, independientemente de las superposiciones.
OPTIONAL_AND_HIDES_LOWER_PRIORITY: Indica que el marcador solo debe mostrarse si no se superpone con otros. Si dos marcadores de este tipo se superponen, se mostrará el que tenga el valor de zIndex más alto. Si tienen el mismo valor de zIndex, se mostrará el que tenga la posición vertical más baja en la pantalla.
REQUIRED_AND_HIDES_OPTIONAL: Indica que el marcador debe mostrarse siempre, independientemente de las superposiciones, y que se deben ocultar los marcadores OPTIONAL_AND_HIDES_LOWER_PRIORITY que se superpongan con él.
En el siguiente ejemplo, se muestra la configuración del comportamiento de colisión de un marcador:
En los mapas de vectores, puedes configurar la altitud en la que aparece un marcador. Esto ayuda a que los marcadores aparezcan correctamente en relación con el contenido del mapa 3D. Para establecer la altitud de un marcador, especifica un valor de LatLngAltitude para la opción MarkerView.position:
TypeScript
constpin=newPinElement({background:'#4b2e83',borderColor:'#b7a57a',glyphColor:'#b7a57a',scale:2.0,});constmarkerView=newAdvancedMarkerElement({map,content:pin.element,// Set altitude to 20 meters above the ground.position:{lat:47.65170843460547,lng:-122.30754,altitude:20}asgoogle.maps.LatLngAltitudeLiteral,});
constpin=newPinElement({background:'#4b2e83',borderColor:'#b7a57a',glyphColor:'#b7a57a',scale:2.0,});constmarkerView=newAdvancedMarkerElement({map,content:pin.element,// Set altitude to 20 meters above the ground.position:{lat:47.65170843460547,lng:-122.30754,altitude:20},});
Cómo controlar la visibilidad de un marcador según el nivel de zoom del mapa
Observa el cambio en la visibilidad de los marcadores (aléjate del mapa):
Para controlar la visibilidad de un Marcador avanzado, crea un objeto de escucha zoom_changed y agrega una función condicional para establecer AdvancedMarkerElement.map en null si el zoom supera el nivel especificado, como se muestra en el siguiente ejemplo:
TypeScript
map.addListener('zoom_changed',()=>{constzoom=map.getZoom();if(zoom){// Only show each marker above a certain zoom level.marker01.map=zoom > 14?map:null;marker02.map=zoom > 15?map:null;marker03.map=zoom > 16?map:null;marker04.map=zoom > 17?map:null;}});
map.addListener('zoom_changed',()=>{constzoom=map.getZoom();if(zoom){// Only show each marker above a certain zoom level.marker01.map=zoom > 14?map:null;marker02.map=zoom > 15?map:null;marker03.map=zoom > 16?map:null;marker04.map=zoom > 17?map:null;}});
[null,null,["Última actualización: 2025-09-02 (UTC)"],[[["\u003cp\u003eThis documentation explains how to manage Advanced Markers, including collision behavior, altitude, and visibility based on zoom level.\u003c/p\u003e\n"],["\u003cp\u003eYou can control marker display during overlaps using \u003ccode\u003eAdvancedMarkerElement.collisionBehavior\u003c/code\u003e with options like \u003ccode\u003eREQUIRED\u003c/code\u003e, \u003ccode\u003eOPTIONAL_AND_HIDES_LOWER_PRIORITY\u003c/code\u003e, and \u003ccode\u003eREQUIRED_AND_HIDES_OPTIONAL\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eOn vector maps, adjust marker altitude using \u003ccode\u003eLatLngAltitude\u003c/code\u003e for the \u003ccode\u003eMarkerView.position\u003c/code\u003e to integrate with 3D map elements.\u003c/p\u003e\n"],["\u003cp\u003eManage marker visibility based on zoom levels by implementing a \u003ccode\u003ezoom_changed\u003c/code\u003e listener that conditionally sets \u003ccode\u003eAdvancedMarkerElement.map\u003c/code\u003e to control display.\u003c/p\u003e\n"],["\u003cp\u003eAdvanced Markers are supported on Android, iOS, and JavaScript platforms with respective documentation available.\u003c/p\u003e\n"]]],["This content details controlling Advanced Marker behavior on maps. Key actions include setting `collisionBehavior` to `REQUIRED`, `OPTIONAL_AND_HIDES_LOWER_PRIORITY`, or `REQUIRED_AND_HIDES_OPTIONAL` to manage marker overlap. Altitude is set using `LatLngAltitude` in the `position` parameter, enabling 3D placement. Marker visibility can be managed with zoom levels by using a `zoom_changed` listener and setting `AdvancedMarkerElement.map` to `null` when the zoom is outside a defined range.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/advanced-markers/collision-behavior \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/advanced-markers/collision-behavior \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/advanced-markers/collision-behavior \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nThis page shows you how to control the following aspects of Advanced Markers:\n\n- Set collision behavior for a marker\n- Set marker altitude\n- Control marker visibility by map zoom level\n\nSet collision behavior for a marker\n\n\nCollision behavior controls how a marker will display if it collides (overlaps)\nwith another marker. Collision behavior is only supported on vector maps.\n\nTo set collision behavior, set `AdvancedMarkerElement.collisionBehavior` to one of\nthe following:\n\n- `REQUIRED`: (default) Always display the marker regardless of collision.\n- `OPTIONAL_AND_HIDES_LOWER_PRIORITY` Display the marker only if it does not overlap with other markers. If two markers of this type would overlap, the one with the higher `zIndex` is shown. If they have the same `zIndex`, the one with the lower vertical screen position is shown.\n- `REQUIRED_AND_HIDES_OPTIONAL` Always display the marker regardless of collision, and hide any `OPTIONAL_AND_HIDES_LOWER_PRIORITY` markers or labels that would overlap with the marker.\n\n| **Note:** On raster maps, only marker-to-marker collisions are detected. Marker collisions with basemap labels are supported only on vector maps.\n\nThe following example shows setting collision behavior for a marker:\n\n\nTypeScript \n\n```typescript\nconst advancedMarker = new AdvancedMarkerElement({\n position: new google.maps.LatLng({ lat, lng }),\n map,\n collisionBehavior: collisionBehavior,\n});https://github.com/googlemaps-samples/js-api-samples/blob/7a62b25fe463fc0fd06949fcd1029aecc8b8504b/dist/samples/advanced-markers-collision/docs/index.ts#L64-L68\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nconst advancedMarker = new AdvancedMarkerElement({\n position: new google.maps.LatLng({ lat, lng }),\n map,\n collisionBehavior: collisionBehavior,\n});https://github.com/googlemaps-samples/js-api-samples/blob/7a62b25fe463fc0fd06949fcd1029aecc8b8504b/dist/samples/advanced-markers-collision/docs/index.js#L49-L53\n```\n\n\u003cbr /\u003e\n\nSet marker altitude\n\n\nOn vector maps, you can set the altitude at which a marker appears. This is\nuseful for making markers appear correctly in relation to 3D map content. To set\nthe altitude for a marker, specify a `LatLngAltitude` as the value for the\n`MarkerView.position` option:\n\n\nTypeScript \n\n```typescript\nconst pin = new PinElement({\n background: '#4b2e83',\n borderColor: '#b7a57a',\n glyphColor: '#b7a57a',\n scale: 2.0,\n});\n\nconst markerView = new AdvancedMarkerElement({\n map,\n content: pin.element,\n // Set altitude to 20 meters above the ground.\n position: { lat: 47.65170843460547, lng: -122.30754, altitude: 20 } as google.maps.LatLngAltitudeLiteral,\n});https://github.com/googlemaps-samples/js-api-samples/blob/7a62b25fe463fc0fd06949fcd1029aecc8b8504b/dist/samples/advanced-markers-altitude/docs/index.ts#L22-L34\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nconst pin = new PinElement({\n background: '#4b2e83',\n borderColor: '#b7a57a',\n glyphColor: '#b7a57a',\n scale: 2.0,\n});\nconst markerView = new AdvancedMarkerElement({\n map,\n content: pin.element,\n // Set altitude to 20 meters above the ground.\n position: { lat: 47.65170843460547, lng: -122.30754, altitude: 20 },\n});https://github.com/googlemaps-samples/js-api-samples/blob/7a62b25fe463fc0fd06949fcd1029aecc8b8504b/dist/samples/advanced-markers-altitude/docs/index.js#L21-L32\n```\n\n\u003cbr /\u003e\n\nControl marker visibility by map zoom level\n\nSee the markers' visibility change (begin by zooming out):\n\n\nTo control the visibility of an Advanced Marker, create a `zoom_changed`\nlistener, and add a conditional function to set `AdvancedMarkerElement.map` to\n`null` if the zoom exceeds the specified level, as shown in the following\nexample:\n\n\nTypeScript \n\n```typescript\nmap.addListener('zoom_changed', () =\u003e {\n const zoom = map.getZoom();\n if (zoom) {\n // Only show each marker above a certain zoom level.\n marker01.map = zoom \u003e 14 ? map : null;\n marker02.map = zoom \u003e 15 ? map : null;\n marker03.map = zoom \u003e 16 ? map : null;\n marker04.map = zoom \u003e 17 ? map : null;\n }\n});https://github.com/googlemaps-samples/js-api-samples/blob/7a62b25fe463fc0fd06949fcd1029aecc8b8504b/dist/samples/advanced-markers-zoom/docs/index.ts#L44-L53\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nmap.addListener('zoom_changed', () =\u003e {\n const zoom = map.getZoom();\n if (zoom) {\n // Only show each marker above a certain zoom level.\n marker01.map = zoom \u003e 14 ? map : null;\n marker02.map = zoom \u003e 15 ? map : null;\n marker03.map = zoom \u003e 16 ? map : null;\n marker04.map = zoom \u003e 17 ? map : null;\n }\n});https://github.com/googlemaps-samples/js-api-samples/blob/7a62b25fe463fc0fd06949fcd1029aecc8b8504b/dist/samples/advanced-markers-zoom/docs/index.js#L38-L47\n```\n\n\u003cbr /\u003e\n\nNext steps\n\n[Make markers clickable and accessible](/maps/documentation/javascript/advanced-markers/accessible-markers)"]]