【问题标题】:google map polyline infowindow谷歌地图折线信息窗口
【发布时间】:2015-06-26 16:43:25
【问题描述】:

作为this question 的延续,我尝试将相应的 json 对象名称添加到 infowindow 内容中,

 var infowindow = new google.maps.InfoWindow({
  content:i
  });

this fiddle 中给出,但它只显示最后一个对象的名称。我也试过return函数作为

google.maps.event.addListener(poly, 'click', (function(event, (poly, i)) {
    return function() {
  infowindow.open(map);
  infowindow.setPosition(event.latLng);
    }
  })(poly, i)); 

但没用 (fiddle)。我怎样才能实现它?

【问题讨论】:

标签: google-maps polyline


【解决方案1】:

您说“但是所有括号都正确闭合。”。这是不正确的(函数定义中有一组额外的括号):

google.maps.event.addListener(poly, 'click', (function(event, (poly, i)) {
    return function() {
      infowindow.open(map);
      infowindow.setPosition(event.latLng);
    }
  })(poly, i)); 

event 参数属于返回函数,只需要对多边形(poly)和循环索引(i)进行闭包:

google.maps.event.addListener(poly, 'click', (function (poly, i) {
    return function (event) {
        infowindow.setContent(""+i);
        infowindow.setPosition(event.latLng);
        infowindow.open(map);
    };
})(poly, i));

updated fiddle

【讨论】:

    猜你喜欢
    • 2013-10-04
    • 2017-01-25
    • 1970-01-01
    • 2016-07-10
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多