Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different Markers in Google Maps with gmaps4rails

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.

like image 771
jmk Avatar asked Oct 12 '22 16:10

jmk


1 Answers

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.

like image 185
jmk Avatar answered Oct 15 '22 11:10

jmk