3

I have a Google Map Version 3 that I can't quite get working as I want. When the map opens there are several markers on the page and clicking or hovering on the marker opens a little InfoBox with the name of the hotel. Clicking on another marker closes the first InfoBox and opens a new one on the new marker. The problem comes with closing the last InfoBox.

If I allow the closeBox in the options, the closeBox (little cross in a square) gets left on the screen when the rest of the InfoBox is closed. This only happens when the InfoBox closes because another one has been opened. As I can't find a solution to this, I intended to do away with the closeBox and let users click a blank area of map to get rid of the final InfoBox. However, at the moment, that doesn't work either.

The problem page can be seen at http://www.littlehotels-testdomain.co.uk/spain/abadia.php (click on "See a location map for this hotel" just to the right of the photo).

The bit of code which should make this work is:

      google.maps.event.addListener(hotelmarker, 'mouseover', function() {
    var ib = new InfoBox(ibOptions);
    boxText.innerHTML = hotelname;
    ib.open(map, hotelmarker);
    });
  google.maps.event.addListener(map, 'click', function() {
    ib.close(map, hotelmarker);
    });

Is there something in the second event listener that I am missing?

TrapezeArtist
  • 777
  • 1
  • 13
  • 38

2 Answers2

5

You need to make your ib (infoBox reference) global. Put it outside your Listener functions.

Eric Bridger
  • 3,751
  • 1
  • 19
  • 34
5

Andy's 47th rule of JavaScript programming: never use a global variable to accomplish something you can do with a single line using jQuery:

$(".infoBox").hide();
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
Andy
  • 51
  • 1
  • 3