您的代码有错误
标题:inspStates[i].name+ "
"+"total: "+inspStates[i].totalInsp+ "
"+ info;
后面的分号是错误的。您正在定义一个对象属性,而不是简单的变量。2.根据您的代码,所有标记都将显示在同一位置(当然,如果center
没有在每次循环迭代中定义)
position: center
也许应该有这样的东西inspStates[i].position
?
UPD
这是我的代码示例。
var places=[
{
position: new google.maps.LatLng(51.5220975, -0.1702880859375),
name: 'first place'
},
{
position: new google.maps.LatLng(51.51, -0.1714),
name: 'second place'
},
{
position: new google.maps.LatLng(51.52205918460975, -0.17380859375),
name: 'third place'
}
];
for(var i=0, len=places.length; i<len; i++)
{
var marker = new google.maps.Marker({
map: map,
position: places[i].position,
title: places[i].name
});
}
也许会有所帮助。此代码显示了三个带有预定义标题的标记。你的代码和我的一样吗?还有一个问题:center
您的代码是否因每次循环迭代而被更改。我已经谈过了,但 oyu 没有发表评论。您能否发布您的代码示例以获得更多帮助?