Search code examples
ruby-on-railsruby-on-rails-3gmaps4rails

Filter markers to hide/show using gmaps4rails?


I am using gmaps4rails (awesome gem!) for some mapping. I've been able to successfully initiate a callback function via javascript and isolate the markers, but cannot call any methods on them as prescribed in the Google maps API documentation. So here, markers gives me an array of my markers but cannot call set visible on any of them.

<script type="text/javascript" charset="utf-8">
     Gmaps.map.callback = function() {
      var markers = Gmaps.map.markers
      Gmaps.map.markers[0].setVisible(true)
      }

Thanks for any help


Solution

  • Simply replace:

    Gmaps.map.markers[0].setVisible(true)
    

    With:

    Gmaps.map.markers[0].serviceObject.setVisible(true)
    

    Actually Gmaps.map.markers[0] contains all info related to a marker + the marker object created from Google map or any other provider.