I've got a problem with Google map markers and I don't find a way to solve it.
I've got a map page view generated with the GMap module where I show certain nodes. I've got also a view block that show some of the same nodes that appear in the map in an unformatted list. What I need is to relate the nodes on the list with their respective markers in the map (so hovering the list change the marker icon or vice versa).
I could relate the nodes with the markers since I've got the exact coordinates of the node which coincide with the marker coordinates (obviously). My problem is that I don't know how to get a list of the existing markers on the map.
From what I've read I should push the markers in an array when they're generated so later I can acces to the markers using the elements in the array, but I couldn't found where does gmap generate the markers. I've tried creating a global array and pushing the markers in the gmap_marker.js
inside:
obj.bind('addmarker', function (marker) {
// ... //
mymarker.push(marker.marker);
}
but even I can see any result. I tried counting the markers that are generated with something like countmarkers += 1;
but the output is also 0.
Anyone has a clue on hou could I achieve this? Any advice would be appreciated.
Edit: Ok, I solved this problem. It looks like what I did was fine and the problem was in the timing of the process. I called:
mymarkers.forEach(function(marker) { //funciona OK alert(marker.getPosition().lat() + ' - ' + marker.getPosition().lng()); });
inside a
setTimeout(function(){});
with a 10ms delay. By increasing the delay to 5000ms all the markers have enough time to be created and I can finally access the markers array.
mymarkersarray[] = marker;
is not valid javascript, start with that