title: Auto close InfoWindow Google Maps API when click another marker
body: <p>I have problem with my Google Maps API v3 script. I am using CodeIgniter framework. 
  The problem is when I clicked a marker, and then click another marker, InfoWindow Google Maps on previous marker didn't close. This is my code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
        var peta;
        var gambar_kantor = new Array();
        var nama     = new Array();
        var kategori = new Array();
        var alamat   = new Array();
        var telpon   = new Array();
        var x        = new Array();
        var y        = new Array();
        var i;
        var url;
        var gambar_marker;
        var gambar_kantor;
        var baseurl  = "&lt;?php echo base_url() ?&gt;";
  
        function map_init() {
            var map = new google.maps.LatLng(-6.990411, 110.422542);
  
  
            var myStyles =[
            {
                featureType: "poi",
                elementType: "labels",
                stylers: [
                      { visibility: "off" }
                ]
            }
            ];
  
            var petaoption = {
                zoom: 12,
                center: map,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                styles: myStyles 
                };
  
            peta = new google.maps.Map(document.getElementById("map_canvas"),petaoption);
  
  
            getdatabase();
        }
  
        function getdatabase(){
            var markers = [];
            var info= [];
  
  
            &lt;?php
          $query = $this-&gt;db-&gt;query("SELECT l.id, l.nama, l.gambar, l.alamat, l.telp, l.latittude, l.longitude, k.nama_kategori, k.ikon
                                      FROM lokasi as l, kategori as k
                                      WHERE l.kategori=k.id");
            $i = 0;
            $js = "";
  
            foreach ($query-&gt;result() as $value) {
  
            $js .= 'nama['.$i.'] = "'.$value-&gt;nama.'";
                    alamat['.$i.'] = "'.$value-&gt;alamat.'";
                    telpon['.$i.'] = "'.$value-&gt;telp.'";
                    x['.$i.'] = "'.$value-&gt;latittude.'";
                    y['.$i.'] = "'.$value-&gt;longitude.'";
                    set_icon("'.$value-&gt;ikon.'");
  
                    var point = new google.maps.LatLng(parseFloat(x['.$i.']),parseFloat(y['.$i.']));
  
                    var contentString = "&lt;table&gt;"+
                                                "&lt;tr&gt;"+
                                                    "&lt;td align=center&gt;&lt;br&gt;&lt;b&gt;" + nama['.$i.'] + "&lt;/b&gt;&lt;/td&gt;"+
                                                "&lt;/tr&gt;"+
                                                "&lt;tr&gt;"+
                                                    "&lt;td align=center width=300px&gt;" + alamat['.$i.'] + "&lt;/td&gt;"+
                                                "&lt;/tr&gt;"+
                                                "&lt;tr&gt;"+
                                                    "&lt;td align=center&gt; Telp: " + telpon['.$i.'] + "&lt;/td&gt;"+
                                                "&lt;/tr&gt;"+
                                            "&lt;/table&gt;";
  
                    var currentInfoWindow = null;
  
                    var infowindow = new google.maps.InfoWindow({
                        content: contentString
  
                    });
  
  
                    var marker = new google.maps.Marker({
                            position: point,
                            map: peta,
                            icon: gambar_marker,
                            clickable: true
                        });
  
  
                    markers.push(marker);
                    info.push(infowindow);
  
  
                    google.maps.event.addListener(markers['.$i.'], "click", function() {
                      info['.$i.'].open(peta,markers['.$i.']); 
                    });
                 ';
              $i++;   
        }
  
        // echo JS
        echo $js;
        ?&gt;
    }
  </code></pre>
  
  <p>Any solution to make InfoWindow auto close when another marker clicked?
  I have tried several solutions on Stackoverflow and Google but didn't worked. Thanks for your kindly help :)</p>