Google maps API v3, can't get clicked marker

HunterM

New Member
I'm getting from my webAPI an array of json objects of users. I can display the marker for each user correctly in their location but I cannot get to work when I click in each of them to get the clicked item, I always get the information from the last in the list.This is the code I use to put them on the map:\[code\]var markers = [];for ( var i = 0; i < size; i++) { var zIndex = membersList.type; var latLng = new google.maps.LatLng(membersList.latitude, membersList.longitude); var marker = new google.maps.Marker({ 'position' : latLng, 'shadow' : null, 'zIndex' : zIndex, 'title' : membersList.username, 'id' : i, 'icon' : markerImage[membersList.type] }); google.maps.event.addListener(marker, 'click', function() { console.log(marker.id); var clicked = membersList[marker.id]; var mType = ['', 'Couple', 'Male', 'Female']; var textType = mType[clicked.type]; var userName = clicked.username; $(this).simpledialog2({ mode: 'button', headerText: "OPTIONS", headerClose: true, buttonPrompt: userName+ ' ('+textType+')', buttons : { 'PROFILE': { click: function () { toUser = userName; loadPage('profile'); }, icon: "info" }, 'MESSAGE': { click: function () { toUser = userName; loadPage('compose'); }, icon: "star", } } }); }); markers.push(marker);}markerCluster.addMarkers(markers);\[/code\]By the way I'm using markerClusterer to display the markers grouped on the map in some zoom levels.
 
Back
Top