问题
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