Bug: event-click-latlng

Abierto
#1,230 1 comentario 0 reacciones 1 asignado Ver en GitHub

@wangela ya está trabajando en esto.

Desde el 26/8/2022.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

Operating system

ubuntu 22.04

Browser Version

Chrome 104.0.5112.101 (oficial) 64 bits

How severe is the bug?

moderate

Bug description

function initMap() {
const myLatlng = { lat: -25.363, lng: 131.044 };

const map = new google.maps.Map(document.getElementById("map")!, {
zoom: 4,
center: myLatlng,
});

// Create the initial InfoWindow.
let infoWindow = new google.maps.InfoWindow({
content: "Click the map to get Lat/Lng!",
position: myLatlng,
});

infoWindow.open(map);

// Configure the click listener.
map.addListener("click", (mapsMouseEvent) => {
// Close the current InfoWindow.
infoWindow.close();

// Create a new InfoWindow.
infoWindow = new google.maps.InfoWindow({
  position: mapsMouseEvent.latLng,
});
infoWindow.setContent(
  JSON.stringify(mapsMouseEvent.latLng.toJSON(), null, 2)
);
infoWindow.open(map);

});
}

declare global {
interface Window {
initMap: () => void;
}
}
window.initMap = initMap;
export {};

Steps to reproduce

Just run.

Console log output
I fixed it by commenting some parts below
 <script>
  function initMap() {
    const myLatlng = { lat: -25.363, lng: 131.044 };

  const map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: myLatlng,
  });

  // Create the initial InfoWindow.
  let infoWindow = new google.maps.InfoWindow({
    content: "Click the map to get Lat/Lng!",
    position: myLatlng,
  });

  infoWindow.open(map);

  // Configure the click listener.
  map.addListener("click", (mapsMouseEvent) => {
    // Close the current InfoWindow.
    infoWindow.close();

    // Create a new InfoWindow.
    infoWindow = new google.maps.InfoWindow({
      position: mapsMouseEvent.latLng,
    });
    infoWindow.setContent(
      JSON.stringify(mapsMouseEvent.latLng.toJSON(), null, 2)
    );
    infoWindow.open(map);
  });
}
/*
declare global {
  interface Window {
    initMap: () => void;
  }
}*/
window.initMap = initMap;
//export {};
    </script>
Lenguaje dominante
TypeScript
Estrellas
804
Forks
826
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de googlemaps/js-samples

Todos los issues de googlemaps/js-samples

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.