【发布时间】:2011-12-09 22:52:27
【问题描述】:
我想在 Googlemap 气泡中显示数组的内容。 我想知道为什么下面的代码不能正常工作,因为我只看到标题而不是气泡中的新闻。
function addMarker(latitude, longitude, title, news)
{
var marker = new GMarker(new GLatLng(latitude, longitude));
GEvent.addListener(marker, 'click',function() {
marker.openInfoWindowHtml(title, news);
});
map.addOverlay(marker);
}
function init()
{
if (GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
for (id = 0; id < markers.length; ++id)
{
addMarker(markers[id].latitude, markers[id].longitude, markers[id].title, markers [id].news); //
}
}
}
window.onload = init;
window.onunload = GUnload;
这是数组结构:
var markers = [
{
'latitude': 56.7382105,
'longitude': 12.8584020,
'title': 'Hallo Planet',
'news': 'blaaaa blaaaa blaaaa.'
},
{
'latitude': 62.6549167,
'longitude': 16.6354329,
'title': 'Hallo World',
'news': 'bla bla bla.'
},
];
我也试过在大括号}后面不加逗号,但结果完全一样。
【问题讨论】:
标签: javascript arrays google-maps-markers