你在你的代碼有錯誤
標題:inspStates [I]。名稱+ 「
」+「 總: 」+ inspStates [I] .totalInsp +「
」 +信息;
尾隨分號錯誤。您正在定義一個對象屬性,但不是簡單變量。 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沒有評論它。 您能否發佈您的代碼示例以獲取更多幫助?
即使在我刪除尾隨分號後,每個狀態的中心都會顯示一個標記作爲計劃bu,但當鼠標懸停時,工具提示未出現 – trs