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) {
  // ... //

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
    – Clive
    May 6, 2016 at 12:35
  • sorry I wrote this without the code in front of me, It's actually something like: 'mymarkers.push(marker);' May 6, 2016 at 12:40

1 Answer 1


Here is a quote from the Comparison of mapping modules:

GMap is considered a legacy module.

So maybe you want to have a look at the IP Geolocation Views & Maps module. Partial quote from its project page:

Despite what the name may suggest, IP Geolocation Views & Maps (IPGV&M) is first and foremost a mapping engine.

The module makes it very easy to create Views-based mapping solutions using the map renderer of your choice (Google, OpenLayers or Leaflet) with any location storage module of your choice, e.g.:

enter image description here

This allows you to bring together modules and feature sets that without IPGV&M you would not be able to combine.

Like beautiful animated marker clustering on Google or Bing or Mapbox ... any of various map providers.

But more importantly IPGV&M adds some features you won't find as conveniently packaged elsewhere.

These include marker differentiation based on field values or ranges (2nd screenshot) with or without font icons, various centering options, super-imposing the current visitor's location, allowing multiple content types to be displayed on the same map, full screen button and mini-map inset (bottom screenshot), polygon support (Geofield), marker tags and tool tips and cross-highlighting of associated content on the page when markers are hovered (and vice versa).

enter image description here

Head over to its (impressive) project page for even more information about it (it would be way too long to include a quote of it all here). That project page also includes various screenshots.

  • Thanks for your answer but my question was more related with the specific issue of acessing the marker js objects of the map. I'll take your answer as a reference for future projects (changing the mapping module would take too much time in the current project which is almost finished). May 6, 2016 at 12:38
  • Merci Miquel for your feedback, and considering it for future projects. About your "... current project ...": There is never time to do it right, but always time to do it again", right? May 6, 2016 at 12:51
  • Off course you're right but that's something which is not in my hands. :) May 6, 2016 at 12:55
  • Yet another way to look at it: first try to make it work with gmap (whatever it takes), trying to deliver what the customer asked for. After you succeeded, suggest the customer a recommended alternative "for the next version of the site" (which didn't make it in the prior version due to deadlines coming close) ... May 6, 2016 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.