I am creating a custom map that shows all the countries and when you click on a marker I would like to use Ajax to retrieve the information for that country. When I first load the map, this is what I get from the server:
..... # { * id: "11" * name: "Algeria" * longitude: "1.6596260" * latitude: "28.0338860" * type: "country" * parent: "1" } # - { * id: "12" * name: "Angola" * longitude: "17.8738870" * latitude: "-11.2026920" * type: "country" * parent: "1" } # - { * id: "13" * name: "Benin" * longitude: "2.3158340" * latitude: "9.3076900" * type: "country" * parent: "1" } ......... And here is my code to create the markers from that JSON : function createMarker(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 marker = new google.maps.Marker({ position: myLatlng, map: map, icon: '/images/map-dot.png', title: countries[i].name }); var id = countries[i].id; google.maps.event.addListener(marker, 'click', function() { getData(id); }); } } } function getData(id) { alert('Get data for this country:'+id); } ======================================================================== When I click on the marker this ID is always 230 (which is the last id in my country list). What am I doing wrong here? How can I have a unique argument for each marker when it calls the getData() function. -- 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 google-maps-js-api...@googlegroups.com. To unsubscribe from this group, send email to google-maps-js-api-v3+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.