无法使用 gmaps4rails 显示自定义标记 [英] Trouble displaying a custom marker using gmaps4rails
问题描述
这个 gem 非常适合显示动态地图.我是一名初级程序员,我似乎无法在地图上显示自定义标记.
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
我尝试了 github README 中提供的信息的多种组合,但都无济于事.我的地图工作得很好,直到上面的代码插入模型......然后所有的标记都消失了.是否需要侧边栏代码才能显示自定义标记?
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
和视图:
<%= gmaps4rails(@markers) %>
我尝试将图像作为选项传递,但无法使其正常工作.
I have tried passing in the image as an option, but could not get it to work.
任何帮助将不胜感激!
推荐答案
在控制器级别,执行:
@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.
这篇关于无法使用 gmaps4rails 显示自定义标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!