开发者

Different Markers in Google Maps with gmaps4rails

开发者 https://www.devze.com 2023-02-12 09:35 出处:网络
With gmaps4rails there is a way to define a custom marker. But the same one is then shown for开发者_开发百科 each database entry.

With gmaps4rails there is a way to define a custom marker. But the same one is then shown for开发者_开发百科 each database entry.

How would I show a different marker for each database entry, like in Google Latitude? Preferably through their own database column or through a sprite, if there are only pictures for categories/groups and not individual users.


Building on apneadivings answer, two possibly shorter ways come to mind:

Generic:

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

In this case, we reuse the category column as the name for the picture:

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

The only thing missing now, is a way to use sprites. But thats probably impossible.

0

精彩评论

暂无评论...
验证码 换一张
取 消