Trouble displaying a custom marker using gmaps4rai

2019-04-13 20:44发布

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!

3条回答
smile是对你的礼貌
2楼-- · 2019-04-13 21:19

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楼-- · 2019-04-13 21:19

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
查看更多
迷人小祖宗
4楼-- · 2019-04-13 21:37

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.

查看更多
登录 后发表回答