Trouble displaying a custom marker using gmaps4rails

自古美人都是妖i 提交于 2019-12-05 05:58:47

问题


This gem is awesome for displaying a dynamic map. I am a beginner programmer, and I cannot seem to get a custom marker to display on the map.

I have the following in my model:

def gmaps4rails_marker_picture
       {
        "picture" => 'images/logo_avatar.png',
         "width" =>  '16',        
         "height" => '16'
         }
  end  

I have tried many combinations of the info provided in the github README, but to no avail. My map works perfectly until the above code gets plugged into the model....then all the markers go away. Is the sidebar code required in order to display a custom marker?

Here is one version of what I have in the controller:

@markers = Property.where(:id => propertyids).to_gmaps4rails

and the view:

<%= gmaps4rails(@markers) %>

I have tried passing in the image as an option, but could not get it to work.

Any help would be much appreciated!


回答1:


At the controller level, do:

@json = Property.where(:id => propertyids).to_gmaps4rails do |property, marker|
  marker.picture({
    "picture" => path_to_image('/images/logo_avatar.png'),
     "width" =>  '16',        
     "height" => '16'
     })
end

It lets you use the assets tag helper.




回答2:


Hey tbone I think I was having a similar issue and found the solution, all I did was change it to this

marker.picture({
                  'picture' => view_context.image_path("green-dot.png"),
                  'width'   => 32,
                  'height'  => 32
                 })



回答3:


the following code works for me, try it..

@json = Property.where(:id => propertyids).to_gmaps4rails do |property, marker|
  marker.picture({
    "picture" => 'assets/logo_avatar.png',
     "width" =>  '16',        
     "height" => '16'
     })
end


来源:https://stackoverflow.com/questions/8498760/trouble-displaying-a-custom-marker-using-gmaps4rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!