[thelist] Googlemap script
Chris Price
chris.price at choctaw.co.uk
Thu Mar 29 07:24:42 CDT 2012
Hi
I've written a script for generating a Google map with several markers,
each with their own location, description and directions.
It works up to the point where I click on a marker to bring up the bubble
with its specific text. The problem is it always shows the last bubble in
my array whichever marker I click.
I know the problem is that its picking up the last variable in a for next
loop but I can't figure out the solution.
I've created a window.map object in another script to generate my variables.
Can anyone shed some light on this please. Script follows:
********
addLoadEvent(function() {
if ((document.getElementById(window.map.mapid))) {
var myOptions = {
zoom: window.map.zoom,
center: new
google.maps.LatLng(window.map.latlng[0],window.map.latlng[1]),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var myMap = new
google.maps.Map(document.getElementById(window.map.canvasid),myOptions);
setMarkers(myMap,window.map.latlngspec);
}
})
function setMarkers(map,locations) {
var shadow = new google.maps.MarkerImage(
window.map.iconshadow,
new google.maps.Size(window.map.shadowsize[0],window.map.shadowsize[1]),
new google.maps.Point(0,0),
new
google.maps.Point(window.map.infowindowanchor[0],window.map.infowindowanchor[1])
);
for (var i = 0; i < locations.length; i++) {
var location = window.map.location[i]
var image = new google.maps.MarkerImage(
window.map.iconimage[i],
new google.maps.Size(window.map.iconsize[0],window.map.iconsize[1]),
new google.maps.Point(0,0),
new
google.maps.Point(window.map.iconanchor[0],window.map.iconanchor[1])
);
var infowindow = new google.maps.InfoWindow({ content:
window.map.bubbletext[i] });
var myLoc = locations[i];
var myLatLng = new google.maps.LatLng(myLoc[1], myLoc[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
shadow: shadow,
icon: image,
title: myLoc[0],
zIndex: myLoc[3]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker); });
}
}
********
Chris.Price
@Choctaw.co.uk <http:\\choctaw.co.uk>
0777 629 0227
Design is my native language
Choctaw Media Ltd is a company registered in England and Wales (04627649)
More information about the thelist
mailing list