Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

324
Visualizações
How to update infowindow of a marker?

enter image description here

 for(i=0; i<locations.length; i++) {
        var position = new google.maps.LatLng(locations[i][2], locations[i][3]);
        var marker = new google.maps.Marker({
            position: position,
            map: map,
        });
        google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
                infowindow.setContent(locations[i][1]);
                infowindow.setOptions({maxWidth: 200});
                infowindow.open(map, marker);               
            }
        }) (marker, i));
        Markers[locations[i][4]] = marker;
    }

I have map has multiple markers with infowindows my aim is to update marker infowindow but could not manage to find a solution.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you are trying to store i in closure then you can do it like this: Demo JsFiddle

  for (let i = 0; i < locations.length; i++) {
    let position = new google.maps.LatLng(locations[i][1], locations[i][2]);
    let marker = new google.maps.Marker({
      position: position,
      map: map,
      title: locations[i][0]
    });

    google.maps.event.addListener(marker, 'click', function (event) {
      let content = `<b>${locations[i][0]} </b><br>
            ${locations[i][3]}<br>
            Position: ${event.latLng.lat()}, ${event.latLng.lng()}`;

      infowindow.setContent(content);
      infowindow.setOptions({ maxWidth: 200 });
      infowindow.open(map, marker);
    });
  }

Or you can get position from event object event.latLng.lat() and get the location using it.


Or you can have separate info window for each marker.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda