Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:15:52+00:00 2026-06-13T02:15:52+00:00

My infowindows are not closing automatically when i click on the other marker.. here

  • 0

My infowindows are not closing automatically when i click on the other marker..
here the code : http://pastebin.com/PvCt2z7W
here is the code for markers with infowindows

 for (var n = 0 ; n <listFavourite.length ; n++)
                    //var favouriteObject =listFavourite[n];
                       addMarker(listFavourite[n]);
                   }           
                   function addMarker(data) {
                       var marker = new google.maps.Marker({
                           position: new google.maps.LatLng(data.lattitude, data.longitude),
                           map: map,
                           title: data.address
                       });

                       var contentString = '<div id="content">'+
                           '<div id="siteNotice">'+
                           '</div>'+
                           '<h2 id="firstHeading" class="firstHeading">'+data.name+'</h2>'+
                           '<div id="bodyContent">'+
                           '<p>'+data.address+'</p>'+
                           '<p></p>'+
                           '<p>Do You Want to change search location</p>'+
                           '<input name="yes" id="yes" type="button" class="btn-common" value="Yes"/>'+
                           '</div>'+
                           '</div>';                                                   
                       var infowindow = new google.maps.InfoWindow({
                       maxWidth: 10,
                       });              
                       google.maps.event.addListener(marker, "click", function() {                     
                           infowindow.setContent(contentString);
                           infowindow.open(map, marker);                       
                       });     
                   };

i tried all the answers here but not able to work it properly
Any suggestions or help Would be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:15:53+00:00Added an answer on June 13, 2026 at 2:15 am

    Instead of creating one infowindow for each marker, have one global infowindow variable. Then all you’re doing in your marker click handler is updating the content for the marker each time. However your code will require this to be done with a closure, otherwise you’re going to get each marker having the last marker’s content.

    var infowindow = new google.maps.InfoWindow({
       maxWidth: 10
    });
    
    var arrMarkers = [];
    
    function addMarker(data) {
       var marker = new google.maps.Marker({
           position: new google.maps.LatLng(data.lattitude, data.longitude),
           map: map,
           title: data.address
       });
    
        arrMarkers.push(marker);
    
       var contentString = '<div id="content">'+
           '<div id="siteNotice">'+
           '</div>'+
           '<h2 id="firstHeading" class="firstHeading">'+data.name+'</h2>'+
           '<div id="bodyContent">'+
           '<p>'+data.address+'</p>'+
           '<p></p>'+
           '<p>Do You Want to change search location</p>'+
           '<input name="yes" id="yes" type="button" class="btn-common" value="Yes"/>'+
           '</div>'+
           '</div>';                                                   
    
    
        // add an event listener for this marker
        bindInfoWindow(marker, map, infowindow, contentString);   
    }
    
    
    function bindInfoWindow(marker, map, infowindow, html) { 
        google.maps.event.addListener(marker, 'click', function() { 
            infowindow.setContent(html); 
            infowindow.open(map, marker); 
        }); 
    }
    
    function clickLink(ID) {
        google.maps.event.trigger(arrMarkers[ID], 'click');
    }
    

    Your HTML of sidebar links might look like:

    <a href="javascript:clickLink(0); return false;">Link 1</a><br>
    <a href="javascript:clickLink(1); return false;">Link 2</a><br>
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've used the code below to display a map with multiple markers and infowindows.
So right clicking creates the markers but when i click on the marker the
I was using the technique described here Click event in Google Map InfoWindow not
Base on this http://jsfiddle.net/kaiser/wzcst/light/ example, but the marker in circle is not accurate, when
I'm not able to open an infoWindow when I select a polygon. Here's my
I am using gmaps.js plugin http://hpneo.github.com/gmaps/ The Sliding Zoom Control and the InfoWindow don't
On click of a marker, I'm opening an InfoWindow on a Google Map. The
I am trying to add infowindows to markers/pushpins on the map. ATM, it is
Good morning. I have the next code which put some markers in a map
The infowindow is not showing properly on my map when clicking on a marker.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.