Search code examples
ruby-on-railsgoogle-mapsgmaps4railsgmaps4rails2

Gmaps4Rails - Custom marker picture not clickable / not opening infowindow


I have a problem with gmaps4rails (2.1.2) when I try to use a custom marker.picture.

This code works perfectly:

Regular GoogleMaps Pin (red) is shown. If I click the Pin, the Infowindow opens.

 @hash = Gmaps4rails.build_markers(@nearbys) do |location, marker|
    marker.title location[:name]
    marker.lat location[:coordinates].y
    marker.lng location[:coordinates].x
    marker.json({title: location[:name]})
  end

When I add a marker.picture the image is shown. But it is not clickable anymore.

 @hash = Gmaps4rails.build_markers(@nearbys) do |location, marker|
    marker.title location[:name]
    marker.lat location[:coordinates].y
    marker.lng location[:coordinates].x
    marker.json({title: location[:name]})
    marker.picture({
                    marker_anchor: [40, 58], # added this optionally <- doesn't work either
                    url: "#{view_context.image_path("map/icons/3dmarker.png") }",
                    width: "44",
                    height: "58"
                   })
  end

Any suggestions what I am doing wrong?

Thank you in advance


Solution

  • Several things:

    • I doubt you have any infowindow working: you dont pass data to create it (marker.infowindow), so it wont be created

    • replace marker_anchor with anchor

    • doing marker.title location[:name] is the same as marker.json({title: location[:name]}) so you have one too many