Search code examples
ruby-on-railsrubygoogle-mapsgmaps4rails

Can't get custom icons working on gmaps4rails


 @hash = Gmaps4rails.build_markers(@additional_infos) do |additional_info, marker|
         marker.lat additional_info.latitude
         marker.lng additional_info.longitude
         marker.picture({
             "picture" => view_context.image_path('/qr-code-icon.png'),
             "width" => 32,
             "height" => 37
         })
       end

This is in my index action of controller. The map shows fine with regular markers but I cant seem to get the custom markers to show. I've tried numerous types of different URLs and ways to link to the icons but no luck.

I've tried "url" = > #{root_url} , http localhost etc.. Pulling my hair out


Solution

  • You must use "url" hash key instead of "picture"

    @hash = Gmaps4rails.build_markers(@additional_infos) do |additional_info, marker| 
      marker.lat additional_info.latitude 
      marker.lng additional_info.longitude 
      marker.picture({
        "url" => view_context.image_path('/qr-code-icon.png'), 
        "width" => 32, 
        "height" => 37 
      })
    end