当我将标记推送到数组时,它会正确绘制标记,并为数组添加标题。
我知道这有效,因为当我在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
,我怎样才能使{{1}}函数拉入其中?{/ p>
答案 0 :(得分:1)
我记得之前做过类似的事情。就我而言,我使用带有圆圈标记的infoWindows。基本上,我在两个单独的数组中。当我创建圆圈标记时,我给它一个唯一的值,称为地方,这基本上是它的计数(创建的 n -th圆的值,是 n < / em>的)。在事件监听器上,我根据当前循环的位置从另一个数组调用了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];
});