0
function bindInfoWindow(marker, map, infoWindow, html) {

    //infoWindow.close(); <---- ignore this one

      google.maps.event.addListener(marker, 'click', function() {

        infoWindow.close();

        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

This is my function with the listener for when a marker is clicked but regardless to what I do the infoWindows will NOT close unless I click them they just stay on the screen when I click them and sometimes I get an error that there is no Close function. Someone help please!

  • possible duplicate of [Google Maps JS API v3 - Simple Multiple Marker Example](http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example) – geocodezip Feb 09 '13 at 23:06

1 Answers1

0

InfoWindow close works just fine. I suspect you are expecting it to close a different infowindow.

In your example it will close the infowindow (if it is open) and open it immediately again, you probably won't see that.

Try adding:

google.maps.event.addListener(map, "click", function() {infoWindow.close();});

Then clicking on the map. Note, this is probably not your final solution, just a technique to show you it does close.

Example

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Wow that worked but when I click another marker the infoWindow stays on the screen. :-/ – Richard Parker Feb 09 '13 at 22:56
  • 1
    What you probably want is only one infoWindow open at a time. See [Multiple InfoWindows](http://stackoverflow.com/questions/11439586/multiple-infowindows/11441073#11441073) or [Google Maps API - opening a single infoWindow](http://stackoverflow.com/questions/7796318/google-maps-api-opening-a-single-infowindow) – geocodezip Feb 09 '13 at 23:05
  • I'm sorry but I am totally lost. – Richard Parker Feb 09 '13 at 23:19
  • If what those posts say doesn't make sense to you, it would be helpful if you could explain why. Or perhaps what you are trying to accomplish along with an example link or jsfiddle. – geocodezip Feb 09 '13 at 23:22
  • I'm sorry I'm not being very helpful What I am trying to do is have a infoWindow pop up when I click a marker and when I click a different Marker the infoWindow from the previous one to close. – Richard Parker Feb 09 '13 at 23:25
  • That is what I call "v2 behavior" (that version of the API did that by default). All the posts that I linked to above and the example in my answer discuss options for achieving that behavior. If you want more advice on _your_ code, you need to add more of your code to the question (and/or provide a link to a live version or a jsfiddle that exhibits the problem that you are trying to fix). – geocodezip Feb 09 '13 at 23:32
  • I tried the links and it wouldn't work the way they demonstrated it I give up I'm going to try bing maps now it makes no sense for this to not work. – Richard Parker Feb 10 '13 at 00:01