JavaScript 谷歌地图 API - 一次打开一个信息窗口..
这个问题与谷歌地图 API v3 中的信息窗口相关。
目前我循环这个函数并放置标记。
function addPostCode(zip, html)
{
geocoder.geocode( { 'address': zip}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
name: zip
});
});
现在我想添加一个具有独特 HTML 的信息窗口,但是我想要以下行为。
打开信息窗口时通过事件,任何当前的信息窗口都将关闭,只留下新的信息窗口。
这可能吗?我将如何处理?事实证明,查找有关此问题的文档很困难。
This questions relating to infowindow in the google maps API v3..
Currently I loop this function and place markers..
function addPostCode(zip, html)
{
geocoder.geocode( { 'address': zip}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
name: zip
});
});
Now I would like to add an info windows with unique HTML, however I would like the following behaviour..
When an infowindow is opened by an event, any current infowindows will close leaving only the new one present..
Is this possible and how would I go about it? Finding documentation on this issue is proving difficult..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在初始化中创建一个信息窗口。在您想要打开信息窗口的事件/侦听器中,您可以设置内容并在地图上的标记/位置上打开信息窗口。
这个问题和答案帮助我解决了单个或多个信息窗口问题:
Google Maps API v3 向每个标记添加信息窗口
Create a single infowindow in your initialization. In your event/listener where you want to open the infowindow, you'd set the content and open the infowindow on the marker/location on the map.
This question and answer helped me out quite a bit with the single or multiple Info Window issue:
Google Maps API v3 adding an InfoWindow to each marker
您最好向 Google 网上论坛询问 Google Maps API v3 关于此问题以及任何其他相关问题。
我没有使用过 API v3,但据我所知,一次只能打开一个信息窗口,所以这会自动发生。
You are probably better off asking the Google Groups for the Google Maps API v3 about this one, and any other related questions.
I haven't used API v3, but as far as I know, you can only have one info window open at a time, so this would happen automatically.
有两种方法可以做到这一点...第一种是创建一个信息窗口并仅使用
.setOptions
信息窗口的方法,用于更新内容
。第二种方法是简单地在代码中设置一个模块级变量来包含“活动”窗口...然后如果有任何 infoWindow 打开,请在您之前调用它的
.close
方法打开新的。There are two ways to do this ... the first is to create a single info window and just use the
.setOptions
method of the info window to update thecontent
.The second way to do it is to simply set a module-level variable in your code to contain the "active" window ... and then if any infoWindow is open, call it's
.close
method before you open the new one.