Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Cuando la función de arrastre se encuentra habilitada, los usuarios pueden arrastrar marcadores en el mapa con el mouse o las teclas de flecha. Si deseas configurar un marcador para que sea arrastrable, establece la propiedad AdvancedMarkerElement.gmpDraggable en true.
En el siguiente ejemplo, aparece un marcador arrastrable que muestra su posición actualizada cuando finaliza el arrastre (se activa el evento dragend):
Para arrastrar un marcador con el teclado, haz lo siguiente:
Presiona la tecla Tab hasta enfocarte en los marcadores.
Usa la tecla de flecha para desplazarte al marcador que deseas arrastrar.
Para activar el arrastre, presiona Opción + Espacio o bien Opción + Intro (Mac), o Alt + Espacioo Alt + Intro (Windows).
Usa las teclas de flecha para mover el marcador.
Para colocar el marcador en una ubicación nueva, presiona la barra espaciadora o Intro. Esta acción también desactivará la función de arrastre.
Para desactivar la función de arrastre y devolver el marcador a su posición anterior, presiona Esc.
Si deseas establecer texto descriptivo para un marcador de modo que sea visible para los lectores de pantalla, usa el atributo AdvancedMarkerElement.title, como se muestra a continuación:
Cuando se configura el atributo title, el texto se vuelve visible para los lectores de pantalla y aparece cuando el cursor se coloca sobre el marcador.
[null,null,["Última actualización: 2025-09-02 (UTC)"],[[["\u003cp\u003eEnable draggable markers on Google Maps by setting the \u003ccode\u003eAdvancedMarkerElement.gmpDraggable\u003c/code\u003e property to \u003ccode\u003etrue\u003c/code\u003e, allowing users to reposition them using the mouse or arrow keys.\u003c/p\u003e\n"],["\u003cp\u003eKeyboard navigation enables marker dragging by focusing, selecting, and moving with arrow keys, using modifier keys (Option/Alt + Space/Enter) to activate dragging and Space/Enter or Esc to drop or cancel.\u003c/p\u003e\n"],["\u003cp\u003eUpon releasing a dragged marker (\u003ccode\u003edragend\u003c/code\u003e event), its updated position can be displayed using an InfoWindow.\u003c/p\u003e\n"],["\u003cp\u003eSet descriptive text for screen readers and mouse hover using the \u003ccode\u003eAdvancedMarkerElement.title\u003c/code\u003e attribute when creating a marker.\u003c/p\u003e\n"]]],["Draggable markers on a map are enabled by setting `AdvancedMarkerElement.gmpDraggable` to `true`. Users can drag markers with the mouse or arrow keys. Keyboard dragging involves tabbing to the marker, activating drag mode with specific key combinations (Option/Alt + Space/Enter), moving with arrow keys, and confirming the new location with Space/Enter or canceling with Esc. The `dragend` event updates and displays the marker's new position. The descriptive text is set by the `AdvancedMarkerElement.title` attribute.\n"],null,["When draggability is enabled, users can drag markers on the map using the mouse\nor the arrow keys. To make a marker draggable, set the `AdvancedMarkerElement.gmpDraggable`\nproperty to `true`.\n\nThe following example map shows a draggable marker that displays its updated\nposition when dragging is finished (the `dragend` event is fired):\n\n\nTo drag a marker with the keyboard:\n\n1. Press the tab key until markers are focused.\n2. Use the arrow key to move to the desired marker.\n3. To activate dragging, press **Option + Space** or **Option + Enter** (Mac), **Alt + Space** or **Alt + Enter** (Windows).\n4. Use the arrow keys to move the marker.\n5. To drop the marker at its new location, press **Space** or **Enter**. This will also turn dragging off.\n6. To turn dragging off and return the marker to its previous position, press **Esc**.\n\nSee the code\n\n\nTypeScript \n\n```typescript\nasync function initMap() {\n // Request needed libraries.\n const { Map, InfoWindow } = await google.maps.importLibrary(\"maps\") as google.maps.MapsLibrary;\n const { AdvancedMarkerElement } = await google.maps.importLibrary(\"marker\") as google.maps.MarkerLibrary;\n\n const map = new Map(document.getElementById('map') as HTMLElement, {\n center: {lat: 37.39094933041195, lng: -122.02503913145092},\n zoom: 14,\n mapId: '4504f8b37365c3d0',\n });\n\n const infoWindow = new InfoWindow();\n\n const draggableMarker = new AdvancedMarkerElement({\n map,\n position: {lat: 37.39094933041195, lng: -122.02503913145092},\n gmpDraggable: true,\n title: \"This marker is draggable.\",\n });\n draggableMarker.addListener('dragend', (event) =\u003e {\n const position = draggableMarker.position as google.maps.LatLng;\n infoWindow.close();\n infoWindow.setContent(`Pin dropped at: ${position.lat}, ${position.lng}`);\n infoWindow.open(draggableMarker.map, draggableMarker);\n });\n\n}\n\ninitMap();https://github.com/googlemaps-samples/js-api-samples/blob/7a62b25fe463fc0fd06949fcd1029aecc8b8504b/dist/samples/advanced-markers-draggable/docs/index.ts#L8-L38\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nasync function initMap() {\n // Request needed libraries.\n const { Map, InfoWindow } = await google.maps.importLibrary(\"maps\");\n const { AdvancedMarkerElement } = await google.maps.importLibrary(\"marker\");\n const map = new Map(document.getElementById('map'), {\n center: { lat: 37.39094933041195, lng: -122.02503913145092 },\n zoom: 14,\n mapId: '4504f8b37365c3d0',\n });\n const infoWindow = new InfoWindow();\n const draggableMarker = new AdvancedMarkerElement({\n map,\n position: { lat: 37.39094933041195, lng: -122.02503913145092 },\n gmpDraggable: true,\n title: \"This marker is draggable.\",\n });\n draggableMarker.addListener('dragend', (event) =\u003e {\n const position = draggableMarker.position;\n infoWindow.close();\n infoWindow.setContent(`Pin dropped at: ${position.lat}, ${position.lng}`);\n infoWindow.open(draggableMarker.map, draggableMarker);\n });\n}\ninitMap();https://github.com/googlemaps-samples/js-api-samples/blob/7a62b25fe463fc0fd06949fcd1029aecc8b8504b/dist/samples/advanced-markers-draggable/docs/index.js#L8-L33\n```\n\n\u003cbr /\u003e\n\nSet descriptive text\n\nTo set descriptive text for a marker, which can be read by screen readers, use\nthe `AdvancedMarkerElement.title` attribute, as shown here: \n\n const markerView = new google.maps.marker.AdvancedMarkerElement({\n map,\n position: { lat: 37.4239163, lng: -122.0947209 },\n title: \"Some descriptive text.\",\n });\n\nWhen the `title` attribute is set, the text is visible to screen readers, and\nwill appear when the mouse hovers over the marker."]]