Reputation: 1891
How do pass color parameter to google maps api using google-maps-for-rails? I would like to set color of each marker inside controller based on a value, so some would be red, some yellow and some green. I believe it is the icon property, in Symbol, looking at:
https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions
Also, I would like to have a number from 1-99 inside the marker, is it possible? So far I have this.
@json = Device.all.to_gmaps4rails do |device, marker|
end
I have been struggling with this for days, any help would be appreciated.
Upvotes: 4
Views: 2486
Reputation: 181
I implemented the above solution to no avail, but now figured out why this wasn't working. Perhaps this was an update to the gem, but "url" is the right key for the URL of the picture, not "picture". Here was my code in my controller:
@devices_hash= Gmaps4rails.build_markers(@devices) do |device, marker|
...
marker.picture({
:url => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|007FFF|000000",
:width => 32,
:height => 32
})
end
Hope this helps some people struggling with the same thing.
Upvotes: 4
Reputation: 115511
You should simply leverage the google's chart api.
Example, the following is a marker with:
FF0000
000000
http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000
So you should customize your needs:
@json = Device.all.to_gmaps4rails do |device, marker|
marker.picture({
:picture => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000", # up to you to pass the proper parameters in the url, I guess with a method from device
:width => 32,
:height => 32
})
end
Upvotes: 15