Google Maps API V3 infoWindow - 所有 infoWindows 显示相同的内容 [英] Google Maps API V3 infoWindow - All infoWindows displaying same content

查看:31
本文介绍了Google Maps API V3 infoWindow - 所有 infoWindows 显示相同的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中,纬度、经度和信息窗口内容存在于名为 obj 的对象数组中.

In my page, latitude, longitude and info window content are present in an array of objects named obj.

所以如果我需要第一个对象的属性纬度,我可以调用 obj[0].latitude.

So if I need the latitude of property of the 1st object, I can call obj[0].latitude.

每个对象的信息窗口内容存储在 obj[i].text 中.

The infoWindow content for each object is stored in obj[i].text.

我正在使用下面的循环来遍历 lat &长值并显示标记和信息窗口.

I'm using the below loop to loop through the lat & long values and display the markers and infoWindows.

<代码>

  for (x=1; x<=obj.length; x++)
  {
      var latlng1 = new google.maps.LatLng(obj[x].latitude, obj[x].longitude);

}

上面的代码有效,但是所有的 infoWindows 都显示了最后一个 obj[i].text 的内容.

The above code works, but all the infoWindows are showing the content of the last obj[i].text.

如何将特定 infoWindow (obj[x].text) 的 infoWindow 内容仅关联到该 infoWindow 实例?

How do I associate the infoWindow content of a particular infoWindow (obj[x].text) to that infoWindow instance only?

如果有人能在不使用 jQuery 或任何其他外部库的情况下指出解决方案会更好.

It would be better if someone can point out a solution without using jQuery or any other external libraries.

谢谢,

推荐答案

BGerrissen 上面的评论很有帮助.

BGerrissen's comment above helped a lot.

我设法在 info 变量上实现了函数关闭.

I managed to achieve function closure on the info variable.

以下 Google 网上论坛帖子说明了如何操作.

The following Google Groups post explains how to.

https://groups.google.com/group/google-maps-api-for-flash/browse_thread/thread/befeb9bf2d1ebcc9

谢谢大家:)

这篇关于Google Maps API V3 infoWindow - 所有 infoWindows 显示相同的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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