Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set marker color when using google-maps-for-rails gem in Rails

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.

like image 929
user1135541 Avatar asked Nov 30 '22 22:11

user1135541


1 Answers

You should simply leverage the google's chart api.

Example, the following is a marker with:

  • letter A
  • red color: FF0000
  • black text: 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
like image 102
apneadiving Avatar answered Dec 06 '22 18:12

apneadiving