Google Maps API V3关闭InfoBox [英] Google Maps API V3 Closing InfoBox

查看:111
本文介绍了Google Maps API V3关闭InfoBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google Map Version 3,我无法按自己的意愿工作。当地图打开时,页面上有多个标记,点击或悬停在标记上打开一个带有酒店名称的小InfoBox。点击另一个标记关闭第一个InfoBox并在新标记上打开一个新的标记。问题出现在关闭最后一个InfoBox中。



如果我允许closeBox在选项中,那么当剩下的时候,closeBox(方块中的小十字)会留在屏幕上的信息框已关闭。这只发生在InfoBox因为另一个已经打开而关闭时。由于找不到解决方案,我打算取消closeBox并让用户点击地图的空白区域以摆脱最终的InfoBox。然而,目前,这也不起作用。



问题页面可以在 http://www.littlehotels-testdomain.co.uk/spain/abadia.php (点击查看该酒店的位置图就在这张照片的右侧)。

应该使这项工作的代码是:

 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);
});

第二个事件侦听器中是否存在我缺少的东西?

解决方案

你需要让你的ib(infoBox引用)全局。把它放在Listener函数之外。


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?

解决方案

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

这篇关于Google Maps API V3关闭InfoBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆