> var country_id = '';
> var country_name = '';
These variables are in global scope. When the marker loop has
finished, they are left pointing at the last set of values.
> google.maps.event.addListener(marker, 'click', function() {
> getData(country_id, country_name);
Whichever marker is clicked, the same set of values is used.
Try
function doMarkers(map, countries)
{
for (var i = 0; i < countries.length; i++)
{
if(countries[i].latitude != null && countries[i].longitude !=
null)
{
var myLatlng = new
google.maps.LatLng(countries[i].latitude,countries[i].longitude);
var myId = countries[i].id ;
var myName = countries[i].name ;
createMarker ( map , myLatlng , myId , myName ) ;
}
}
}
function createMarker ( map, latlng, id, name )
{
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: '/images/map-dot.png',
title: name
});
google.maps.event.addListener(marker, 'click', function() {
getData(id, name);
});
}
--
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.