5

使用gmaps4rails可以定义自定义标记。但随后会为每个数据库条目显示相同的条目。

如何为每个数据库条目显示不同的标记,例如在谷歌纵横中?如果只有类别/组的图片而不是个人用户,最好通过他们自己的数据库列或通过精灵。

4

1 回答 1

4

基于 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

现在唯一缺少的是一种使用精灵的方法。但这可能是不可能的。

于 2011-02-18T17:04:23.353 回答