I would like to display the content of an array in a Googlemap bubble.
I wonder why the following code is not working properly, since I only see the title but not the news in the bubble.
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;
And this is the array structure:
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.'
},
];
I tried also without the comma after the curly bracket } but the result is exactly the same.
Google’s “openInfoWindowHtml” accepts two parameters, but not those. See their documentation on this.
To format a title and body in that info window, you need to combine both “title” and “news” elements into one string (with HTML formatting). Or, you could use “openInfoWindow” with a pre-made DOM node ready-to-go instead. Try:
Does that work better?