Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had the exact same problem: I don't know why, but when you loop on Gmaps.map.markers and try to bind a mouseover listener function, it will always evaluate the marker variable as the last marker in the loop.</p> <p>My workaround is: don't use the marker variable in your mouseover function, use <code>this</code> instead which is a <a href="https://developers.google.com/maps/documentation/javascript/reference#Marker" rel="nofollow" title="Gmaps Marker">Gmaps Marker</a> object, loop on Gmaps.map.markers and find the one that matches.</p> <p>Here is the modification for your code:</p> <pre><code>$(document).on 'map:ready', -&gt; addHoverHandlers() addHoverHandlers = -&gt; # m is Gmap4Rails marker, doc in gmaps4rails.base.js.coffee for m in Gmaps.map.markers # marker is a Google Maps Marker # https://developers.google.com/maps/documentation/javascript/reference#Marker marker = m.serviceObject console.log marker.getPosition().toString() # Show the infowindow when user mouses-in google.maps.event.addListener marker, "mouseover", -&gt; console.log marker.getPosition().toString() # Loop on Gmaps.map.markers and find the one using this for m2 in Gmaps.map.markers if m2.serviceObject == this m2.infowindow.open m2.serviceObject.map, m2.serviceObject # Hide the infowindow when user mouses-out google.maps.event.addListener marker, "mouseout", -&gt; m.infowindow.close() </code></pre> <p>I know it's a very inefficient way to implement the mouseover function. At least, it works.</p> <p>hth</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload