当我将标记推入数组时,它会正确绘制标记,并向数组添加标题。
我知道这有效,因为当我 console.log 时console.log(markersArray);
它返回以下内容。标记的标题是next door
.
下面是我的标记单击,打开了信息窗口,但是当我 console.log 出被称为的数据时mll
它里面没有标题。
google.maps.event.addListener(marker, 'click', function(mll) {
console.log(mll);
var html= "<div style='color:#000;background-color:#fff;padding:5px;width:150px;'><p>"+mll+"</p></div>";
iw = new google.maps.InfoWindow({content:html});
iw.open(map,marker);
});
我怎样才能得到click
函数来拉入title
当数组拥有它并成功推送它时?
我记得以前做过类似的事情。就我而言,我使用带有圆形标记的 infoWindows。本质上,我将两者放在不同的数组中。当我制作圆形标记时,我给了它一个唯一的值,称为位置,这基本上是它的计数(n创建了第 - 个圆圈,是n)。在事件侦听器上,我根据当前圆的位置从另一个数组调用 infoWindow。
你可以做一个数组var titles = [];
持有头衔。
每次创建新标记时,都会增加一个var count = 0;
,记录您有多少个标记。
在您的标记选项中,添加place: count
。当您需要特定标题时,可以致电titles[marker.place];
var infos = [];
var count = 0;
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var lastWindow;
count++;
var populationOptions = {
//leaving out defaults
place: count
};
var circle = new google.maps.Circle(populationOptions);
lastCircle = circle;
var contentString = 'just a string...';
var infowindow = new google.maps.InfoWindow({
content: contentString,
position: new google.maps.LatLng(data.lon, data.lad)
});
infos.push(infowindow);
google.maps.event.addListener(circle, 'mouseover', function() {
if(lastWindow){
lastWindow.close();
}
infos[circle.place].open(map);
lastWindow = infos[circle.place];
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)