This is the code I used from the beginning, but I hade problem with
the content in the infoWindow showing the content from an old
infoWindow.
<script type='text/javascript'>
// GoogleMapScript
function initialize() {
var latlng = new google.maps.LatLng(55.6762944,12.5681157);
var settings = {
zoom: 11,
center: latlng,
mapTypeControl: true,
scaleControl: true,
mapTypeControlOptions: {style:
google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style:
google.maps.NavigationControlStyle.DEFAULT},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
settings);
// Declare infowindow as a global variable
var infowindow;
// Creating an array wich will contain the tooltip for markers
var tooltip_names=[];
// Adding information
tooltip_names.push('Kommandantens Gaard');
tooltip_names.push('Bikuben Kollegiet');
tooltip_names.push('Tietgenkollegiet');
// Creating an array which will contain the coordinates for the cities
var places=[];
// Adding a LatLng object for each city
places.push(new google.maps.LatLng(55.667093,12.581255));
places.push(new google.maps.LatLng(55.662767,12.593293));
places.push(new google.maps.LatLng(55.660794,12.58972));
// Creating an array wich will contain info in Info Windows
var infow = [];
// Adding info to Info Windows
infow.push("<div><a href='?p=visa&id=0001'><img src='../bilder/
bilder_medium/0001_2m.jpg' width='150' height='113' border='0' /></
a><br /><a href='?p=visa&id=0001'>Kommandantens Gaard</a></div>");
infow.push("<div><a href='?p=visa&id=0002'><img src='../bilder/
bilder_medium/0002_1m.jpg' width='150' height='113' border='0' /></
a><br /><a href='?p=visa&id=0002'>Bikuben Kollegiet</a></div>");
infow.push("<div><a href='?p=visa&id=0003'><img src='../bilder/
bilder_medium/0003_1m.jpg' width='150' height='113' border='0' /></
a><br /><a href='?p=visa&id=0003'>Tietgenkollegiet</a></div>");
// Loop to create Markers and Info Windows
for (var i = 0; i < places.length; i += 1) {
// Call function
addMarker(places[i], i);
}
// Creating Markers and Info Windows
function addMarker(latlng,no) {
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: 'http://google-maps-icons.googlecode.com/files/factory.png',
title: tooltip_names[no]
});
// Add click event to the marker
google.maps.event.addListener(marker, 'click', function() {
// Check to see if the infowindow already exists and is not null
if (!infowindow) {
// if the infowindow doesn't exist,create an
// empty InfoWindow object
infowindow = new google.maps.InfoWindow();
}
// Set the content of the InfoWindow
infowindow.setContent(infow[no]);
// Tie the InfoWindow to the marker
infowindow.open(map,marker);
});
}
}
</script>
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.