与 gmaps4rails有办法define a custom marker .但是每个数据库条目都会显示相同的条目。
我如何为每个数据库条目显示不同的标记,就像在谷歌纵横中一样?如果只有类别/组的图片而不是个人用户,最好通过他们自己的数据库列或通过 sprite。
最佳答案
基于 apneadivings 的回答,我想到了两种可能更短的方法:
通用的:
def gmaps4rails_marker_picture
{
"picture" => self.image_path, # image_path column has to contain something like '/assets/my_pic.jpg'.
"width" => 32, #beware to resize your pictures properly
"height" => 32 #beware to resize your pictures properly
}
end
在这种情况下,我们重用类别列作为图片的名称:
def gmaps4rails_marker_picture
{
"picture" => "/images/" + self.category + ".png",
"width" => 32, #beware to resize your pictures properly
"height" => 32 #beware to resize your pictures properly
}
end
现在唯一缺少的是使用 Sprite 的方法。但这可能是不可能的。
关于ruby-on-rails - 带有 gmaps4rails 的谷歌地图中的不同标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5042591/